0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/integration-tests/tests/resource.ts
simeng-li 162998f414
refactor(test): refactor integration test step 1 (#1684)
* chore(test): integration test update

add dotenv

* chore(core): update pnpm lock

update pnpm lock

* refactor(test): refactor integration test step 1

extract api, and orgnize test case following core/route structure

* chore(test): update path

update path

* fix(test): update path

update path

* fix(test): cr update
cr update
2022-07-27 03:23:10 +00:00

56 lines
2 KiB
TypeScript

import { managementResource } from '@logto/schemas/lib/seeds';
import { HTTPError } from 'got';
import { createResource, getResource, updateResource, deleteResource } from '@/api';
import { generateResourceIndicator, generateResourceName } from '@/utils';
describe('admin console api resources', () => {
it('should get management api resource details successfully', async () => {
const fetchedManagementApiResource = await getResource(managementResource.id);
expect(fetchedManagementApiResource).toMatchObject(managementResource);
});
it('should create api resource successfully', async () => {
const resourceName = generateResourceName();
const resourceIndicator = generateResourceIndicator();
const createdResource = await createResource(resourceName, resourceIndicator);
expect(createdResource.name).toBe(resourceName);
expect(createdResource.indicator).toBe(resourceIndicator);
const fetchedCreatedResource = await getResource(createdResource.id);
expect(fetchedCreatedResource).toBeTruthy();
});
it('should update api resource details successfully', async () => {
const resource = await createResource();
expect(resource).toBeTruthy();
const newResourceName = `new_${resource.name}`;
const newAccessTokenTtl = resource.accessTokenTtl + 100;
const updatedResource = await updateResource(resource.id, {
name: newResourceName,
accessTokenTtl: newAccessTokenTtl,
});
expect(updatedResource.id).toBe(resource.id);
expect(updatedResource.name).toBe(newResourceName);
expect(updatedResource.accessTokenTtl).toBe(newAccessTokenTtl);
});
it('should delete api resource successfully', async () => {
const createdResource = await createResource();
expect(createdResource).toBeTruthy();
await deleteResource(createdResource.id);
const response = await getResource(createdResource.id).catch((error: unknown) => error);
expect(response instanceof HTTPError && response.response.statusCode === 404).toBe(true);
});
});