mirror of
https://github.com/strapi/strapi.git
synced 2025-11-07 21:58:23 +00:00
Run test on both content manager and generated apis in the same test suite
This commit is contained in:
parent
d786217d06
commit
8f6ca1c0ac
@ -5,12 +5,15 @@ const { createAuthRequest } = require('../../../../test/helpers/request');
|
|||||||
let modelsUtils;
|
let modelsUtils;
|
||||||
let rq;
|
let rq;
|
||||||
|
|
||||||
describe('Non repeatable and Non required group', () => {
|
describe.each([
|
||||||
|
['CONTENT MANAGER', '/content-manager/explorer/withgroup'],
|
||||||
|
['GENERATED API', '/withgroups'],
|
||||||
|
])('[%s] => Non repeatable and Not required group for', (_, path) => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const token = await registerAndLogin();
|
const token = await registerAndLogin();
|
||||||
rq = createAuthRequest(token);
|
const authRq = createAuthRequest(token);
|
||||||
|
|
||||||
modelsUtils = createModelsUtils({ rq });
|
modelsUtils = createModelsUtils({ rq: authRq });
|
||||||
|
|
||||||
await modelsUtils.createGroup({
|
await modelsUtils.createGroup({
|
||||||
name: 'somegroup',
|
name: 'somegroup',
|
||||||
@ -26,6 +29,10 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
repeatable: false,
|
repeatable: false,
|
||||||
required: false,
|
required: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rq = authRq.defaults({
|
||||||
|
baseUrl: `http://localhost:1337${path}`,
|
||||||
|
});
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
@ -35,7 +42,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
|
|
||||||
describe('POST new entry', () => {
|
describe('POST new entry', () => {
|
||||||
test('Creating entry with JSON works', async () => {
|
test('Creating entry with JSON works', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -53,7 +60,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Creating entry with formdata works', async () => {
|
test('Creating entry with formdata works', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
formData: {
|
formData: {
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
field: {
|
field: {
|
||||||
@ -75,7 +82,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
test.each([[], 'someString', 128219, false])(
|
test.each([[], 'someString', 128219, false])(
|
||||||
'Throws if the field is not an object %p',
|
'Throws if the field is not an object %p',
|
||||||
async value => {
|
async value => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: value,
|
field: value,
|
||||||
},
|
},
|
||||||
@ -86,7 +93,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
test('Can send a null value', async () => {
|
test('Can send a null value', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: null,
|
field: null,
|
||||||
},
|
},
|
||||||
@ -97,7 +104,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Can send input without the group field', async () => {
|
test('Can send input without the group field', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {},
|
body: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -108,7 +115,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
|
|
||||||
describe('GET entries', () => {
|
describe('GET entries', () => {
|
||||||
test('Should return entries with their nested groups', async () => {
|
test('Should return entries with their nested groups', async () => {
|
||||||
const res = await rq.get('/content-manager/explorer/withgroup');
|
const res = await rq.get('/');
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
expect(res.statusCode).toBe(200);
|
||||||
expect(Array.isArray(res.body)).toBe(true);
|
expect(Array.isArray(res.body)).toBe(true);
|
||||||
@ -124,7 +131,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
|
|
||||||
describe('PUT entry', () => {
|
describe('PUT entry', () => {
|
||||||
test('Keeps the previous value if group not sent', async () => {
|
test('Keeps the previous value if group not sent', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -132,26 +139,21 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateRes = await rq.put(
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`,
|
|
||||||
{
|
|
||||||
body: {},
|
body: {},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(updateRes.statusCode).toBe(200);
|
expect(updateRes.statusCode).toBe(200);
|
||||||
expect(updateRes.body).toEqual(res.body);
|
expect(updateRes.body).toEqual(res.body);
|
||||||
|
|
||||||
const getRes = await rq.get(
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(getRes.statusCode).toBe(200);
|
expect(getRes.statusCode).toBe(200);
|
||||||
expect(getRes.body).toEqual(res.body);
|
expect(getRes.body).toEqual(res.body);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Removes previous group if null sent', async () => {
|
test('Removes previous group if null sent', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -159,14 +161,11 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateRes = await rq.put(
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`,
|
|
||||||
{
|
|
||||||
body: {
|
body: {
|
||||||
field: null,
|
field: null,
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const expectResult = {
|
const expectResult = {
|
||||||
id: res.body.id,
|
id: res.body.id,
|
||||||
@ -176,16 +175,14 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
expect(updateRes.statusCode).toBe(200);
|
expect(updateRes.statusCode).toBe(200);
|
||||||
expect(updateRes.body).toMatchObject(expectResult);
|
expect(updateRes.body).toMatchObject(expectResult);
|
||||||
|
|
||||||
const getRes = await rq.get(
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(getRes.statusCode).toBe(200);
|
expect(getRes.statusCode).toBe(200);
|
||||||
expect(getRes.body).toMatchObject(expectResult);
|
expect(getRes.body).toMatchObject(expectResult);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Replaces the previous group if sent without id', async () => {
|
test('Replaces the previous group if sent without id', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -193,16 +190,13 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateRes = await rq.put(
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`,
|
|
||||||
{
|
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'new String',
|
name: 'new String',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(updateRes.statusCode).toBe(200);
|
expect(updateRes.statusCode).toBe(200);
|
||||||
expect(updateRes.body.field.id).not.toBe(res.body.field.id);
|
expect(updateRes.body.field.id).not.toBe(res.body.field.id);
|
||||||
@ -213,9 +207,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const getRes = await rq.get(
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(getRes.statusCode).toBe(200);
|
expect(getRes.statusCode).toBe(200);
|
||||||
expect(getRes.body).toMatchObject({
|
expect(getRes.body).toMatchObject({
|
||||||
@ -227,7 +219,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Throws on invalid id in group', async () => {
|
test('Throws on invalid id in group', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -235,23 +227,20 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateRes = await rq.put(
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`,
|
|
||||||
{
|
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
id: 'invalid_id',
|
id: 'invalid_id',
|
||||||
name: 'new String',
|
name: 'new String',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
expect(updateRes.statusCode).toBe(400);
|
expect(updateRes.statusCode).toBe(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Updates group if previsous group id is sent', async () => {
|
test('Updates group if previsous group id is sent', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -259,17 +248,14 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateRes = await rq.put(
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`,
|
|
||||||
{
|
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
id: res.body.field.id, // send old id to update the previous group
|
id: res.body.field.id, // send old id to update the previous group
|
||||||
name: 'new String',
|
name: 'new String',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
id: res.body.id,
|
id: res.body.id,
|
||||||
@ -282,9 +268,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
expect(updateRes.statusCode).toBe(200);
|
expect(updateRes.statusCode).toBe(200);
|
||||||
expect(updateRes.body).toMatchObject(expectedResult);
|
expect(updateRes.body).toMatchObject(expectedResult);
|
||||||
|
|
||||||
const getRes = await rq.get(
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(getRes.statusCode).toBe(200);
|
expect(getRes.statusCode).toBe(200);
|
||||||
expect(getRes.body).toMatchObject(expectedResult);
|
expect(getRes.body).toMatchObject(expectedResult);
|
||||||
@ -293,7 +277,7 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
|
|
||||||
describe('DELETE entry', () => {
|
describe('DELETE entry', () => {
|
||||||
test('Returns entry with groups', async () => {
|
test('Returns entry with groups', async () => {
|
||||||
const res = await rq.post('/content-manager/explorer/withgroup', {
|
const res = await rq.post('/', {
|
||||||
body: {
|
body: {
|
||||||
field: {
|
field: {
|
||||||
name: 'someString',
|
name: 'someString',
|
||||||
@ -301,16 +285,12 @@ describe('Non repeatable and Non required group', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const deleteRes = await rq.delete(
|
const deleteRes = await rq.delete(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(deleteRes.statusCode).toBe(200);
|
expect(deleteRes.statusCode).toBe(200);
|
||||||
expect(deleteRes.body).toMatchObject(res.body);
|
expect(deleteRes.body).toMatchObject(res.body);
|
||||||
|
|
||||||
const getRes = await rq.get(
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
`/content-manager/explorer/withgroup/${res.body.id}`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(getRes.statusCode).toBe(404);
|
expect(getRes.statusCode).toBe(404);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user