mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 23:44:08 +00:00
fix exists function
This commit is contained in:
parent
4d27d9de51
commit
f2c6af61ee
@ -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');
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -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('');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user