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 boolean', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
|
|
|
|
modelsUtils = createModelsUtils({ rq });
|
|
|
|
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.createContentTypeWithType('withboolean', 'boolean');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.deleteContentType('withboolean');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Create entry with value input JSON', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean',
|
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create entry with value input FromData', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean',
|
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: true }),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-18 09:02:48 +01:00
|
|
|
test('Throws on invalid boolean value', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
let res = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean',
|
|
|
|
{
|
|
|
|
body: { field: 'random' },
|
|
|
|
}
|
|
|
|
);
|
2020-02-18 09:02:48 +01:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
test('Convert integer to boolean value', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
let res = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean',
|
|
|
|
{
|
|
|
|
body: { field: 1 },
|
|
|
|
}
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: true,
|
|
|
|
});
|
|
|
|
|
2020-11-02 12:40:35 +01:00
|
|
|
res = await rq.post('/content-manager/collection-types/application::withboolean.withboolean', {
|
2020-02-18 09:02:48 +01:00
|
|
|
body: { field: 0 },
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Reading entry, returns correct value', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.get(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean'
|
|
|
|
);
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(Array.isArray(res.body)).toBe(true);
|
|
|
|
expect(res.body).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
expect.objectContaining({
|
|
|
|
field: expect.any(Boolean),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry sets the right value and format', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/collection-types/application::withboolean.withboolean',
|
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
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::withboolean.withboolean/${res.body.id}`,
|
2019-08-08 10:41:05 +02:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(updateRes.statusCode).toBe(200);
|
|
|
|
expect(updateRes.body).toMatchObject({
|
2019-08-08 10:47:53 +02:00
|
|
|
id: res.body.id,
|
2019-08-08 10:41:05 +02:00
|
|
|
field: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|