mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Merge pull request #14192 from strapi/api-token-v2/regenerate-tokens-api
Api Token v2/add regenerate controller tests
This commit is contained in:
commit
7ed24a9edf
@ -258,6 +258,62 @@ describe('API Token Controller', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Regenerate an API token', () => {
|
||||
const token = {
|
||||
id: 1,
|
||||
name: 'api-token_tests-regenerate',
|
||||
description: 'api-token_tests-description',
|
||||
type: 'read-only',
|
||||
};
|
||||
|
||||
test('Regenerates an API token successfully', async () => {
|
||||
const regenerate = jest.fn().mockResolvedValue(token);
|
||||
const getById = jest.fn().mockResolvedValue(token);
|
||||
const created = jest.fn();
|
||||
const ctx = createContext({ params: { id: token.id } }, { created });
|
||||
|
||||
global.strapi = {
|
||||
admin: {
|
||||
services: {
|
||||
'api-token': {
|
||||
regenerate,
|
||||
getById,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await apiTokenController.regenerate(ctx);
|
||||
|
||||
expect(regenerate).toHaveBeenCalledWith(token.id);
|
||||
});
|
||||
|
||||
test('Fails if token not found', async () => {
|
||||
const regenerate = jest.fn().mockResolvedValue(token);
|
||||
const getById = jest.fn().mockResolvedValue(null);
|
||||
const created = jest.fn();
|
||||
const notFound = jest.fn();
|
||||
const ctx = createContext({ params: { id: token.id } }, { created, notFound });
|
||||
|
||||
global.strapi = {
|
||||
admin: {
|
||||
services: {
|
||||
'api-token': {
|
||||
regenerate,
|
||||
getById,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await apiTokenController.regenerate(ctx);
|
||||
|
||||
expect(regenerate).not.toHaveBeenCalled();
|
||||
expect(getById).toHaveBeenCalledWith(token.id);
|
||||
expect(notFound).toHaveBeenCalledWith('API Token not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Retrieve an API token', () => {
|
||||
const token = {
|
||||
id: 1,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user