2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-04-29 11:11:46 +02:00
|
|
|
const { createTestBuilder } = require('../../../../../test/helpers/builder');
|
|
|
|
const { createStrapiInstance } = require('../../../../../test/helpers/strapi');
|
|
|
|
const { createAuthRequest } = require('../../../../../test/helpers/request');
|
2019-08-08 10:41:05 +02:00
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
const builder = createTestBuilder();
|
|
|
|
let strapi;
|
2019-08-08 10:41:05 +02:00
|
|
|
let rq;
|
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
const ct = {
|
|
|
|
name: 'withenumeration',
|
|
|
|
attributes: {
|
|
|
|
field: {
|
|
|
|
type: 'enumeration',
|
|
|
|
enum: ['one', 'two'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-08 10:41:05 +02:00
|
|
|
describe('Test type enumeration', () => {
|
|
|
|
beforeAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await builder.addContentType(ct).build();
|
2019-08-08 10:41:05 +02:00
|
|
|
|
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
|
|
|
});
|
2019-08-08 10:41:05 +02: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
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
test('Create entry value enumeration input JSON', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withenumeration.withenumeration',
|
2019-11-15 11:49:32 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'one',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200); // should return 201
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 'one',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Reading entry, returns correct value', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.get(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withenumeration.withenumeration'
|
2019-11-15 11:49:32 +01:00
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
2020-11-03 13:42:01 +01:00
|
|
|
expect(res.body.pagination).toBeDefined();
|
|
|
|
expect(Array.isArray(res.body.results)).toBe(true);
|
|
|
|
res.body.results.forEach(entry => {
|
2019-08-08 10:41:05 +02:00
|
|
|
expect(['one', 'two'].includes(entry.field)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry sets the right value and format', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withenumeration.withenumeration',
|
2019-11-15 11:49:32 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'two',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
const updateRes = await rq.put(
|
2020-11-02 12:40:35 +01:00
|
|
|
`/content-manager/collection-types/application::withenumeration.withenumeration/${res.body.id}`,
|
2019-08-08 10:41:05 +02:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'one',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(updateRes.statusCode).toBe(200);
|
|
|
|
expect(updateRes.body).toMatchObject({
|
|
|
|
id: res.body.id,
|
|
|
|
field: 'one',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-18 09:02:48 +01:00
|
|
|
test('Allows null value', async () => {
|
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withenumeration.withenumeration',
|
2020-02-18 09:02:48 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: null,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200); // should return 201
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: null,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Throws an error when the enumeration value is not in the options', async () => {
|
|
|
|
const res = await rq.post(
|
2020-11-02 12:40:35 +01:00
|
|
|
'/content-manager/collection-types/application::withenumeration.withenumeration',
|
2020-02-18 09:02:48 +01:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'invalid-value',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
});
|