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.test.ts
simeng-li 939dc0eac8
refactor(test): refactor logto client and actions (#1691)
* refactor(test): refactor logto client and actions

refactor logto client and related actions

* chore(test): rename LogtoClient class

rename LogtoClient class

* refactor(test): rename client and client methods

rename client and client methods

* refactor(test): cr fix

cr fix

* refactor(test): reuse helpers

reuser helpers
2022-07-28 10:13:21 +08: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);
});
});