mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
test(console): integration tests for api resources (#1622)
This commit is contained in:
parent
6e96d73a7c
commit
b88722674c
2 changed files with 80 additions and 0 deletions
|
@ -8,3 +8,6 @@ export const extractCookie = (response: Response) => {
|
|||
|
||||
export const generateUsername = () => `usr_${crypto.randomUUID().replaceAll('-', '_')}`;
|
||||
export const generatePassword = () => `pwd_${crypto.randomUUID()}`;
|
||||
|
||||
export const generateResourceName = () => `res_${crypto.randomUUID()}`;
|
||||
export const generateResourceIndicator = () => `https://${crypto.randomUUID()}.logto.io`;
|
||||
|
|
77
packages/integration-tests/tests/api-resources.test.ts
Normal file
77
packages/integration-tests/tests/api-resources.test.ts
Normal file
|
@ -0,0 +1,77 @@
|
|||
import type { Resource } from '@logto/schemas';
|
||||
import { managementResource } from '@logto/schemas/lib/seeds';
|
||||
|
||||
import { authedAdminApi } from '@/api';
|
||||
import { generateResourceIndicator, generateResourceName } from '@/utils';
|
||||
|
||||
const createResource = (name?: string, indicator?: string) =>
|
||||
authedAdminApi
|
||||
.post('resources', {
|
||||
json: {
|
||||
name: name ?? generateResourceName(),
|
||||
indicator: indicator ?? generateResourceIndicator(),
|
||||
},
|
||||
})
|
||||
.json<Resource>();
|
||||
|
||||
describe('admin console api resources', () => {
|
||||
it('should get management api resource details successfully', async () => {
|
||||
const fetchedManagementApiResource = await authedAdminApi
|
||||
.get(`resources/${managementResource.id}`)
|
||||
.json<Resource>();
|
||||
|
||||
expect(fetchedManagementApiResource).toMatchObject(managementResource);
|
||||
});
|
||||
|
||||
it('should create api resource successfully', async () => {
|
||||
const resourceName = 'gallery';
|
||||
const resourceIndicator = 'https://gallery.logto.io';
|
||||
|
||||
const createdResource = await createResource(resourceName, resourceIndicator);
|
||||
|
||||
expect(createdResource.name).toBe(resourceName);
|
||||
expect(createdResource.indicator).toBe(resourceIndicator);
|
||||
|
||||
const fetchedCreatedResource = await authedAdminApi
|
||||
.get(`resources/${createdResource.id}`)
|
||||
.json<Resource>();
|
||||
|
||||
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 authedAdminApi
|
||||
.patch(`resources/${resource.id}`, {
|
||||
json: {
|
||||
name: newResourceName,
|
||||
accessTokenTtl: newAccessTokenTtl,
|
||||
},
|
||||
})
|
||||
.json<Resource>();
|
||||
|
||||
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 authedAdminApi.delete(`resources/${createdResource.id}`);
|
||||
|
||||
const fetchResponseAfterDeletion = await authedAdminApi.get(`resources/${createdResource.id}`, {
|
||||
throwHttpErrors: false,
|
||||
});
|
||||
|
||||
expect(fetchResponseAfterDeletion.statusCode).toBe(404);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue