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 string', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
const token = await registerAndLogin();
|
|
|
|
rq = createAuthRequest(token);
|
|
|
|
|
|
|
|
modelsUtils = createModelsUtils({ rq });
|
|
|
|
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.createContentTypeWithType('withstring', 'string');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2019-12-12 10:15:25 +01:00
|
|
|
await modelsUtils.deleteContentType('withstring');
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Creates an entry with JSON', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withstring.withstring', {
|
|
|
|
body: {
|
|
|
|
field: 'Some string',
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: 'Some string',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Creates an entry with formData', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withstring.withstring', {
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: '"Some string"' }),
|
|
|
|
},
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
field: '"Some string"',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Reading entry, returns correct value', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.get('/content-manager/explorer/application::withstring.withstring');
|
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(String),
|
|
|
|
}),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry with JSON sets the right value and format', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withstring.withstring', {
|
|
|
|
body: { field: 'Some string' },
|
|
|
|
});
|
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::withstring.withstring/${res.body.id}`,
|
2019-08-08 10:41:05 +02:00
|
|
|
{
|
|
|
|
body: { field: 'Updated string' },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
expect(updateRes.statusCode).toBe(200);
|
|
|
|
expect(updateRes.body).toMatchObject({
|
|
|
|
id: res.body.id,
|
|
|
|
field: 'Updated string',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry with Formdata sets the right value and format', async () => {
|
2020-03-02 15:18:08 +01:00
|
|
|
const res = await rq.post('/content-manager/explorer/application::withstring.withstring', {
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: 'Some string' }),
|
|
|
|
},
|
|
|
|
});
|
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::withstring.withstring/${res.body.id}`,
|
2019-08-08 10:41:05 +02:00
|
|
|
{
|
|
|
|
formData: {
|
|
|
|
data: JSON.stringify({ field: 'Updated string' }),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
expect(updateRes.statusCode).toBe(200);
|
|
|
|
expect(updateRes.body).toMatchObject({
|
|
|
|
id: res.body.id,
|
|
|
|
field: 'Updated string',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|