mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 22:51:33 +00:00
Fix basic core api tests
This commit is contained in:
parent
a618bcf24c
commit
0e3cc07627
@ -67,10 +67,18 @@ describe('Core API - Basic', () => {
|
|||||||
body: product,
|
body: product,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
const { statusCode, body } = res;
|
||||||
expect(res.body).toMatchObject(product);
|
|
||||||
expect(res.body.published_at).toBeUndefined();
|
expect(statusCode).toBe(200);
|
||||||
data.product.push(res.body);
|
expect(body).toMatchObject({
|
||||||
|
data: {
|
||||||
|
id: expect.anything(),
|
||||||
|
attributes: product,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(body.data.attributes.published_at).toBeUndefined();
|
||||||
|
|
||||||
|
data.product.push(body.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Read product', async () => {
|
test('Read product', async () => {
|
||||||
@ -79,18 +87,26 @@ describe('Core API - Basic', () => {
|
|||||||
url: '/products',
|
url: '/products',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
const { statusCode, body } = res;
|
||||||
expect(Array.isArray(res.body)).toBe(true);
|
|
||||||
expect(res.body).toHaveLength(1);
|
expect(statusCode).toBe(200);
|
||||||
expect(res.body).toEqual(
|
expect(Array.isArray(body.data)).toBe(true);
|
||||||
|
expect(body.data).toHaveLength(1);
|
||||||
|
expect(body.data).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
name: 'Product 1',
|
id: expect.anything(),
|
||||||
description: 'Product description',
|
attributes: expect.objectContaining({
|
||||||
|
name: 'Product 1',
|
||||||
|
description: 'Product description',
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
res.body.forEach(p => expect(p.published_at).toBeUndefined());
|
|
||||||
|
body.data.forEach(p => {
|
||||||
|
expect(p.attributes.published_at).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Update product', async () => {
|
test('Update product', async () => {
|
||||||
@ -104,11 +120,17 @@ describe('Core API - Basic', () => {
|
|||||||
body: product,
|
body: product,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
const { statusCode, body } = res;
|
||||||
expect(res.body).toMatchObject(product);
|
|
||||||
expect(res.body.id).toEqual(data.product[0].id);
|
expect(statusCode).toBe(200);
|
||||||
expect(res.body.published_at).toBeUndefined();
|
expect(body.data).toMatchObject({
|
||||||
data.product[0] = res.body;
|
attributes: product,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(body.data.id).toEqual(data.product[0].id);
|
||||||
|
expect(body.data.attributes.published_at).toBeUndefined();
|
||||||
|
|
||||||
|
data.product[0] = res.body.data;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Delete product', async () => {
|
test('Delete product', async () => {
|
||||||
@ -117,10 +139,12 @@ describe('Core API - Basic', () => {
|
|||||||
url: `/products/${data.product[0].id}`,
|
url: `/products/${data.product[0].id}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
const { statusCode, body } = res;
|
||||||
expect(res.body).toMatchObject(data.product[0]);
|
|
||||||
expect(res.body.id).toEqual(data.product[0].id);
|
expect(statusCode).toBe(200);
|
||||||
expect(res.body.published_at).toBeUndefined();
|
expect(body.data).toMatchObject(data.product[0]);
|
||||||
|
expect(body.data.id).toEqual(data.product[0].id);
|
||||||
|
expect(body.data.attributes.published_at).toBeUndefined();
|
||||||
data.product.shift();
|
data.product.shift();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user