2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2023-04-05 10:32:20 +02:00
|
|
|
const { createTestBuilder } = require('api-tests/builder');
|
|
|
|
const { createStrapiInstance } = require('api-tests/strapi');
|
|
|
|
const { createAuthRequest } = require('api-tests/request');
|
2020-02-13 11:35:36 +01:00
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
let strapi;
|
2020-02-13 11:35:36 +01:00
|
|
|
let rq;
|
|
|
|
|
|
|
|
describe('Test type UID', () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
describe('No targetField, required=false, not length limits', () => {
|
|
|
|
const model = {
|
2021-09-13 16:57:04 +02:00
|
|
|
displayName: 'With uid',
|
|
|
|
singularName: 'withuid',
|
|
|
|
pluralName: 'withuids',
|
2020-11-17 15:38:41 +01:00
|
|
|
attributes: {
|
|
|
|
slug: {
|
|
|
|
type: 'uid',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-02-13 11:35:36 +01:00
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
const builder = createTestBuilder();
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await builder.addContentType(model).build();
|
|
|
|
|
2020-11-30 20:20:36 +01:00
|
|
|
strapi = await createStrapiInstance();
|
2020-11-17 15:38:41 +01:00
|
|
|
rq = await createAuthRequest({ strapi });
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
afterAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await strapi.destroy();
|
|
|
|
await builder.cleanup();
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
test('Creates an entry successfully', async () => {
|
2021-08-06 18:09:49 +02:00
|
|
|
const res = await rq.post('/content-manager/collection-types/api::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: 'valid-uid',
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'valid-uid',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-20 17:30:05 +02:00
|
|
|
// TODO: to handle with database UniqueError
|
|
|
|
test.skip('Throws error on duplicate value', async () => {
|
2021-08-06 18:09:49 +02:00
|
|
|
const res = await rq.post('/content-manager/collection-types/api::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
});
|
|
|
|
|
2021-08-06 18:09:49 +02:00
|
|
|
const conflicting = await rq.post('/content-manager/collection-types/api::withuid.withuid', {
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(conflicting.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Can set value to be null', async () => {
|
2021-08-06 18:09:49 +02:00
|
|
|
const res = await rq.post('/content-manager/collection-types/api::withuid.withuid', {
|
2020-03-02 15:18:08 +01:00
|
|
|
body: {
|
|
|
|
slug: null,
|
|
|
|
},
|
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('No targetField, required, no length limits', () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
const model = {
|
2021-09-13 16:57:04 +02:00
|
|
|
displayName: 'withrequireduid',
|
|
|
|
singularName: 'withrequireduid',
|
|
|
|
pluralName: 'withrequireduids',
|
2020-11-17 15:38:41 +01:00
|
|
|
attributes: {
|
|
|
|
slug: {
|
|
|
|
type: 'uid',
|
|
|
|
required: true,
|
2020-02-13 11:35:36 +01:00
|
|
|
},
|
2020-11-17 15:38:41 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const builder = createTestBuilder();
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await builder.addContentType(model).build();
|
|
|
|
|
2020-11-30 20:20:36 +01:00
|
|
|
strapi = await createStrapiInstance();
|
2020-11-17 15:38:41 +01:00
|
|
|
rq = await createAuthRequest({ strapi });
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
afterAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await strapi.destroy();
|
|
|
|
await builder.cleanup();
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2020-02-13 11:35:36 +01:00
|
|
|
|
|
|
|
test('Creates an entry successfully', async () => {
|
|
|
|
const res = await rq.post(
|
2021-08-06 18:09:49 +02:00
|
|
|
'/content-manager/collection-types/api::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'valid-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'valid-uid',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-10-20 17:30:05 +02:00
|
|
|
// TODO: to handle with database UniqueError
|
|
|
|
test.skip('Throws error on duplicate value', async () => {
|
2020-02-13 11:35:36 +01:00
|
|
|
const res = await rq.post(
|
2021-08-06 18:09:49 +02:00
|
|
|
'/content-manager/collection-types/api::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
});
|
|
|
|
|
|
|
|
const conflicting = await rq.post(
|
2021-08-06 18:09:49 +02:00
|
|
|
'/content-manager/collection-types/api::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
slug: 'duplicate-uid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(conflicting.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Cannot set value to be null', async () => {
|
|
|
|
const res = await rq.post(
|
2021-08-06 18:09:49 +02:00
|
|
|
'/content-manager/collection-types/api::withrequireduid.withrequireduid',
|
2020-02-13 11:35:36 +01:00
|
|
|
{
|
2020-02-17 15:54:49 +01:00
|
|
|
body: {
|
|
|
|
slug: null,
|
|
|
|
},
|
2020-02-13 11:35:36 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|