mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 06:07:41 +00:00
fix tests for mongo
Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
parent
970a470034
commit
1746314930
@ -11,8 +11,11 @@ const data = {
|
|||||||
rolesWithUsers: [],
|
rolesWithUsers: [],
|
||||||
rolesWithoutUsers: [],
|
rolesWithoutUsers: [],
|
||||||
users: [],
|
users: [],
|
||||||
|
deleteRolesIds: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const omitTimestamps = obj => _.omit(obj, ['updatedAt', 'createdAt', 'updated_at', 'created_at']);
|
||||||
|
|
||||||
describe('Role CRUD End to End', () => {
|
describe('Role CRUD End to End', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const token = await registerAndLogin();
|
const token = await registerAndLogin();
|
||||||
@ -41,8 +44,6 @@ describe('Role CRUD End to End', () => {
|
|||||||
id: expect.anything(),
|
id: expect.anything(),
|
||||||
name: role.name,
|
name: role.name,
|
||||||
description: role.description,
|
description: role.description,
|
||||||
created_at: expect.anything(),
|
|
||||||
updated_at: expect.anything(),
|
|
||||||
});
|
});
|
||||||
data.rolesWithoutUsers.push(res.body.data);
|
data.rolesWithoutUsers.push(res.body.data);
|
||||||
});
|
});
|
||||||
@ -118,10 +119,9 @@ describe('Role CRUD End to End', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
expect(res.statusCode).toBe(200);
|
||||||
expect(res.body.data).toMatchObject({
|
expect(omitTimestamps(res.body.data)).toMatchObject({
|
||||||
...data.rolesWithoutUsers[0],
|
...omitTimestamps(data.rolesWithoutUsers[0]),
|
||||||
...updates,
|
...updates,
|
||||||
updated_at: expect.anything(),
|
|
||||||
});
|
});
|
||||||
data.rolesWithoutUsers[0] = res.body.data;
|
data.rolesWithoutUsers[0] = res.body.data;
|
||||||
});
|
});
|
||||||
@ -137,10 +137,9 @@ describe('Role CRUD End to End', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
expect(res.statusCode).toBe(200);
|
||||||
expect(res.body.data).toMatchObject({
|
expect(omitTimestamps(res.body.data)).toMatchObject({
|
||||||
...data.rolesWithoutUsers[0],
|
...omitTimestamps(data.rolesWithoutUsers[0]),
|
||||||
...updates,
|
...updates,
|
||||||
updated_at: expect.anything(),
|
|
||||||
});
|
});
|
||||||
data.rolesWithoutUsers[0] = res.body.data;
|
data.rolesWithoutUsers[0] = res.body.data;
|
||||||
});
|
});
|
||||||
@ -162,24 +161,6 @@ describe('Role CRUD End to End', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test("Cannot update a role if it doesn't exist", async () => {
|
|
||||||
const updates = {
|
|
||||||
name: "new name - Cannot update a role if it doesn't exist",
|
|
||||||
description: "new description - Cannot update a role if it doesn't exist",
|
|
||||||
};
|
|
||||||
const res = await rq({
|
|
||||||
url: '/admin/roles/1000', // id that doesn't exist
|
|
||||||
method: 'PUT',
|
|
||||||
body: updates,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res.statusCode).toBe(404);
|
|
||||||
expect(res.body).toMatchObject({
|
|
||||||
statusCode: 404,
|
|
||||||
error: 'Not Found',
|
|
||||||
message: 'entry.notFound',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('Delete roles', () => {
|
describe('Delete roles', () => {
|
||||||
describe('batch-delete', () => {
|
describe('batch-delete', () => {
|
||||||
@ -221,6 +202,7 @@ describe('Role CRUD End to End', () => {
|
|||||||
});
|
});
|
||||||
expect(res.statusCode).toBe(404);
|
expect(res.statusCode).toBe(404);
|
||||||
|
|
||||||
|
data.deleteRolesIds.push(data.rolesWithoutUsers[0].id);
|
||||||
data.rolesWithoutUsers.shift();
|
data.rolesWithoutUsers.shift();
|
||||||
});
|
});
|
||||||
test('Can delete two roles', async () => {
|
test('Can delete two roles', async () => {
|
||||||
@ -241,19 +223,10 @@ describe('Role CRUD End to End', () => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
expect(res.statusCode).toBe(404);
|
expect(res.statusCode).toBe(404);
|
||||||
|
data.deleteRolesIds.push(data.rolesWithoutUsers[0].id);
|
||||||
data.rolesWithoutUsers.shift();
|
data.rolesWithoutUsers.shift();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
test("No error if deleting a role that doesn't exist", async () => {
|
|
||||||
const res = await rq({
|
|
||||||
url: '/admin/roles/batch-delete',
|
|
||||||
method: 'POST',
|
|
||||||
body: { ids: ['id-that-doesnt-exist'] },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
|
||||||
expect(res.body.data).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
describe('simple delete', () => {
|
describe('simple delete', () => {
|
||||||
test('Can delete a role', async () => {
|
test('Can delete a role', async () => {
|
||||||
@ -270,17 +243,9 @@ describe('Role CRUD End to End', () => {
|
|||||||
});
|
});
|
||||||
expect(res.statusCode).toBe(404);
|
expect(res.statusCode).toBe(404);
|
||||||
|
|
||||||
|
data.deleteRolesIds.push(data.rolesWithoutUsers[0].id);
|
||||||
data.rolesWithoutUsers.shift();
|
data.rolesWithoutUsers.shift();
|
||||||
});
|
});
|
||||||
test("No error if deleting a role that doesn't exist", async () => {
|
|
||||||
const res = await rq({
|
|
||||||
url: '/admin/roles/id-that-doesnt-exist',
|
|
||||||
method: 'DELETE',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(res.statusCode).toBe(200);
|
|
||||||
expect(res.body.data).toEqual(null);
|
|
||||||
});
|
|
||||||
test("Don't delete a role if it still has assigned users", async () => {
|
test("Don't delete a role if it still has assigned users", async () => {
|
||||||
let res = await rq({
|
let res = await rq({
|
||||||
url: `/admin/roles/${data.rolesWithUsers[0].id}`,
|
url: `/admin/roles/${data.rolesWithUsers[0].id}`,
|
||||||
@ -301,6 +266,45 @@ describe('Role CRUD End to End', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("Roles don't exist", () => {
|
||||||
|
test("Cannot update a role if it doesn't exist", async () => {
|
||||||
|
const updates = {
|
||||||
|
name: "new name - Cannot update a role if it doesn't exist",
|
||||||
|
description: "new description - Cannot update a role if it doesn't exist",
|
||||||
|
};
|
||||||
|
const res = await rq({
|
||||||
|
url: `/admin/roles/${data.deleteRolesIds[0]}`,
|
||||||
|
method: 'PUT',
|
||||||
|
body: updates,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(404);
|
||||||
|
expect(res.body).toMatchObject({
|
||||||
|
statusCode: 404,
|
||||||
|
error: 'Not Found',
|
||||||
|
message: 'entry.notFound',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test("Simple delete - No error if deleting a role that doesn't exist", async () => {
|
||||||
|
const res = await rq({
|
||||||
|
url: `/admin/roles/${data.deleteRolesIds[0]}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body.data).toEqual(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test("Batch Delete - No error if deleting a role that doesn't exist", async () => {
|
||||||
|
const res = await rq({
|
||||||
|
url: '/admin/roles/batch-delete',
|
||||||
|
method: 'POST',
|
||||||
|
body: { ids: [data.deleteRolesIds[0]] },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body.data).toEqual([]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edition === 'CE') {
|
if (edition === 'CE') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user