add test to support trimming

This commit is contained in:
Dieter Stinglhamber 2021-08-27 16:35:34 +02:00
parent 4b7a1eb48f
commit e16ce91ade
2 changed files with 27 additions and 1 deletions

View File

@ -14,7 +14,9 @@ module.exports = {
* - having only spaces as value;
*/
attributes.name = attributes.name.trim();
attributes.description = attributes.description.trim();
if (attributes.description) {
attributes.description = attributes.description.trim();
}
try {
await validateApiTokenCreationInput(attributes);

View File

@ -12,6 +12,7 @@ const { createAuthRequest } = require('../../../../../test/helpers/request');
* 2. Fails to creates an api token (invalid `type` in the body)
* 3. Creates an api token (successfully)
* 4. Creates an api token without a description (successfully)
* 5. Creates an api token with trimmed description and name (successfully)
*/
describe('Admin API Token CRUD (e2e)', () => {
@ -120,4 +121,27 @@ describe('Admin API Token CRUD (e2e)', () => {
id: expect.any(Number),
});
});
test('5. Creates an api token with trimmed description and name (successfully)', async () => {
const body = {
name: 'api-token_tests-name-with-spaces-at-the-end ',
description: 'api-token_tests-description-with-spaces-at-the-end ',
type: 'read-only',
};
const res = await rq({
url: '/admin/api-tokens',
method: 'POST',
body,
});
expect(res.statusCode).toBe(201);
expect(res.body.data).toMatchObject({
accessKey: expect.any(String),
name: 'api-token_tests-name-with-spaces-at-the-end',
description: 'api-token_tests-description-with-spaces-at-the-end',
type: body.type,
id: expect.any(Number),
});
});
});