2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
const { createTestBuilder } = require('../../../../test/helpers/builder');
|
|
|
|
const { createStrapiInstance } = require('../../../../test/helpers/strapi');
|
2019-08-08 10:41:05 +02:00
|
|
|
const { createAuthRequest } = require('../../../../test/helpers/request');
|
|
|
|
|
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: 'withstring',
|
|
|
|
attributes: {
|
|
|
|
field: {
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-08 10:41:05 +02:00
|
|
|
describe('Test type string', () => {
|
|
|
|
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 });
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await strapi.destroy();
|
|
|
|
await builder.cleanup();
|
2019-08-08 10:41:05 +02:00
|
|
|
}, 60000);
|
|
|
|
|
|
|
|
test('Creates an entry with JSON', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.post(
|
|
|
|
'/content-manager/collection-types/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('Reading entry, returns correct value', async () => {
|
2020-11-02 12:40:35 +01:00
|
|
|
const res = await rq.get(
|
|
|
|
'/content-manager/collection-types/application::withstring.withstring'
|
|
|
|
);
|
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 => {
|
|
|
|
expect(entry.field).toEqual(expect.any(String));
|
|
|
|
});
|
2019-08-08 10:41:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Updating entry with JSON 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::withstring.withstring',
|
|
|
|
{
|
|
|
|
body: { field: 'Some string' },
|
|
|
|
}
|
|
|
|
);
|
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::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',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|