fix exists function

This commit is contained in:
Dieter Stinglhamber 2021-08-27 08:47:27 +02:00
parent 4d27d9de51
commit f2c6af61ee
3 changed files with 7 additions and 7 deletions

View File

@ -14,7 +14,7 @@ module.exports = {
return ctx.badRequest('ValidationError', err);
}
if (apiTokenService.exists({ name: attributes.name })) {
if (await apiTokenService.exists({ name: attributes.name })) {
return ctx.badRequest('Name already taken');
}

View File

@ -7,10 +7,10 @@ const crypto = require('crypto');
* @param {string} attributes.name
* @param {string} [attributes.description]
*
* @returns boolean
* @returns Promise<boolean>
*/
const exists = (attributes = {}) => {
return strapi.query('strapi::api-token').count({ where: attributes }) > 0;
const exists = async (attributes = {}) => {
return (await strapi.query('strapi::api-token').count({ where: attributes })) > 0;
};
/**

View File

@ -65,7 +65,7 @@ describe('Admin API Token CRUD (e2e)', () => {
expect(res.statusCode).toBe(201);
expect(res.body.data).not.toBeNull();
expect(res.body.data.id).toBeDefined();
expect(res.body.data.id).toBe(1);
expect(res.body.data.accessKey).toBeDefined();
expect(res.body.data.name).toBe(body.name);
expect(res.body.data.description).toBe(body.description);
@ -74,7 +74,7 @@ describe('Admin API Token CRUD (e2e)', () => {
test('3. Creates an api token without a description (successfully)', async () => {
const body = {
name: 'api-token_tests-name',
name: 'api-token_tests-name-without-description',
type: 'read-only',
};
@ -86,7 +86,7 @@ describe('Admin API Token CRUD (e2e)', () => {
expect(res.statusCode).toBe(201);
expect(res.body.data).not.toBeNull();
expect(res.body.data.id).toBeDefined();
expect(res.body.data.id).toBe(2);
expect(res.body.data.accessKey).toBeDefined();
expect(res.body.data.name).toBe(body.name);
expect(res.body.data.description).toBe('');