2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-08-08 10:41:05 +02:00
|
|
|
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
|
|
|
const createModelsUtils = require('../../../../test/helpers/models');
|
|
|
|
const { createAuthRequest } = require('../../../../test/helpers/request');
|
|
|
|
|
|
|
|
let modelsUtils;
|
|
|
|
let rq;
|
|
|
|
|
|
|
|
describe('Test type enumeration', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
|
|
|
|
modelsUtils = createModelsUtils({ rq });
|
|
|
|
|
2020-02-18 09:02:48 +01:00
|
|
|
await modelsUtils.createContentTypeWithType('withenumeration', 'enumeration', {
|
|
|
|
enum: ['one', 'two'],
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.deleteContentType('withenumeration');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Create entry value enumeration input JSON', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration',
|
|
|
|
{
|
|
|
|
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('Create entry value enumeration input Formdata', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration',
|
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: 'two' }),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200); // should return 201
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 'two',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Reading entry, returns correct value', async () => {
|
2019-11-15 11:49:32 +01:00
|
|
|
const res = await rq.get(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration'
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(Array.isArray(res.body)).toBe(true);
|
|
|
|
res.body.forEach(entry => {
|
|
|
|
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(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration',
|
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'two',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
const updateRes = await rq.put(
|
2019-11-15 11:49:32 +01:00
|
|
|
`/content-manager/explorer/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(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration',
|
|
|
|
{
|
|
|
|
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(
|
|
|
|
'/content-manager/explorer/application::withenumeration.withenumeration',
|
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 'invalid-value',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
});
|