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 integer', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
|
|
|
|
modelsUtils = createModelsUtils({ rq });
|
|
|
|
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.createContentTypeWithType('withinteger', 'integer');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.deleteContentType('withinteger');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Create entry with value input JSON', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withinteger.withinteger', {
|
|
|
|
body: {
|
|
|
|
field: 123456,
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 123456,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Create entry with value input Fromdata', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withinteger.withinteger', {
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: 123456 }),
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 123456,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// I don't think it will work everywhere ...
|
|
|
|
test('Create entry with a string should cast the value', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withinteger.withinteger', {
|
|
|
|
body: {
|
|
|
|
field: '123456',
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 123456,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Reading entry, returns correct value', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.get('/content-manager/explorer/application::withinteger.withinteger');
|
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(Number.isInteger(entry.field)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry sets the right value and format', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withinteger.withinteger', {
|
|
|
|
body: {
|
|
|
|
field: 123,
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
const updatedRes = await rq.put(
|
2019-11-15 11:49:32 +01:00
|
|
|
`/content-manager/explorer/application::withinteger.withinteger/${res.body.id}`,
|
2019-08-08 10:41:05 +02:00
|
|
|
{
|
|
|
|
body: {
|
|
|
|
field: 543,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(updatedRes.statusCode).toBe(200);
|
|
|
|
expect(updatedRes.body).toMatchObject({
|
|
|
|
id: res.body.id,
|
|
|
|
field: 543,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|