2022-07-20 22:37:51 -05:00
|
|
|
import { managementResource } from '@logto/schemas/lib/seeds';
|
2022-07-26 22:23:10 -05:00
|
|
|
import { HTTPError } from 'got';
|
2022-07-20 22:37:51 -05:00
|
|
|
|
2022-07-26 22:23:10 -05:00
|
|
|
import { createResource, getResource, updateResource, deleteResource } from '@/api';
|
2022-07-20 22:37:51 -05:00
|
|
|
import { generateResourceIndicator, generateResourceName } from '@/utils';
|
|
|
|
|
|
|
|
describe('admin console api resources', () => {
|
|
|
|
it('should get management api resource details successfully', async () => {
|
2022-07-26 22:23:10 -05:00
|
|
|
const fetchedManagementApiResource = await getResource(managementResource.id);
|
2022-07-20 22:37:51 -05:00
|
|
|
|
|
|
|
expect(fetchedManagementApiResource).toMatchObject(managementResource);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create api resource successfully', async () => {
|
2022-07-21 05:36:04 -05:00
|
|
|
const resourceName = generateResourceName();
|
|
|
|
const resourceIndicator = generateResourceIndicator();
|
2022-07-20 22:37:51 -05:00
|
|
|
|
|
|
|
const createdResource = await createResource(resourceName, resourceIndicator);
|
|
|
|
|
|
|
|
expect(createdResource.name).toBe(resourceName);
|
|
|
|
expect(createdResource.indicator).toBe(resourceIndicator);
|
|
|
|
|
2022-07-26 22:23:10 -05:00
|
|
|
const fetchedCreatedResource = await getResource(createdResource.id);
|
2022-07-20 22:37:51 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-07-26 22:23:10 -05:00
|
|
|
const updatedResource = await updateResource(resource.id, {
|
|
|
|
name: newResourceName,
|
|
|
|
accessTokenTtl: newAccessTokenTtl,
|
|
|
|
});
|
2022-07-20 22:37:51 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-07-26 22:23:10 -05:00
|
|
|
await deleteResource(createdResource.id);
|
2022-07-20 22:37:51 -05:00
|
|
|
|
2022-07-26 22:23:10 -05:00
|
|
|
const response = await getResource(createdResource.id).catch((error: unknown) => error);
|
|
|
|
expect(response instanceof HTTPError && response.response.statusCode === 404).toBe(true);
|
2022-07-20 22:37:51 -05:00
|
|
|
});
|
|
|
|
});
|