chore: use snapshot property matchers instead of 'omit' (#98)
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
exports[`backupNg .create() : creates a new backup job with schedules 1`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"mode": "full",
|
||||
"name": "default-backupNg",
|
||||
"settings": Any<Object>,
|
||||
"type": "backup",
|
||||
"userId": Any<String>,
|
||||
"vms": Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
},
|
||||
@@ -15,12 +18,15 @@ exports[`backupNg .create() : creates a new backup job with schedules 2`] = `
|
||||
Object {
|
||||
"cron": "0 * * * * *",
|
||||
"enabled": false,
|
||||
"id": Any<String>,
|
||||
"jobId": Any<String>,
|
||||
"name": "scheduleTest",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`backupNg .create() : creates a new backup job without schedules 1`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"mode": "full",
|
||||
"name": "default-backupNg",
|
||||
"settings": Object {
|
||||
@@ -29,6 +35,7 @@ Object {
|
||||
},
|
||||
},
|
||||
"type": "backup",
|
||||
"userId": Any<String>,
|
||||
"vms": Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { findKey, omit } from "lodash";
|
||||
import { findKey } from "lodash";
|
||||
import { noSuchObject } from "xo-common/api-errors";
|
||||
|
||||
import config from "../_config";
|
||||
@@ -28,7 +28,10 @@ describe("backupNg", () => {
|
||||
describe(".create() :", () => {
|
||||
it("creates a new backup job without schedules", async () => {
|
||||
const backupNg = await xo.createTempBackupNgJob(defaultBackupNg);
|
||||
expect(omit(backupNg, "id", "userId")).toMatchSnapshot();
|
||||
expect(backupNg).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
expect(backupNg.userId).toBe(xo._user.id);
|
||||
});
|
||||
|
||||
@@ -50,7 +53,11 @@ describe("backupNg", () => {
|
||||
|
||||
const backupNgJob = await xo.call("backupNg.getJob", { id: jobId });
|
||||
|
||||
expect(omit(backupNgJob, "id", "userId", "settings")).toMatchSnapshot();
|
||||
expect(backupNgJob).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
settings: expect.any(Object),
|
||||
});
|
||||
expect(backupNgJob.userId).toBe(xo._user.id);
|
||||
|
||||
const settingKeys = Object.keys(backupNgJob.settings);
|
||||
@@ -61,7 +68,10 @@ describe("backupNg", () => {
|
||||
});
|
||||
|
||||
const schedule = await xo.call("schedule.get", { id: scheduleId });
|
||||
expect(omit(schedule, "id", "jobId")).toMatchSnapshot();
|
||||
expect(schedule).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
jobId: expect.any(String),
|
||||
});
|
||||
expect(schedule.jobId).toBe(jobId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
exports[`job .create() : creates a new job 1`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest",
|
||||
@@ -21,6 +22,7 @@ Object {
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"userId": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -34,6 +36,7 @@ exports[`job .get() : fails trying to get a job with a non existent id 1`] = `[J
|
||||
|
||||
exports[`job .get() : gets an existing job 1`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest",
|
||||
@@ -53,60 +56,67 @@ Object {
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"userId": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`job .getAll() : gets all available jobs 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest",
|
||||
"paramsVector": Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"type": "set",
|
||||
"values": Array [
|
||||
Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
"name": "test-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"type": "crossProduct",
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest",
|
||||
"paramsVector": Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"type": "set",
|
||||
"values": Array [
|
||||
Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
"name": "test-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"type": "crossProduct",
|
||||
},
|
||||
Object {
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest2",
|
||||
"paramsVector": Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"type": "set",
|
||||
"values": Array [
|
||||
Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
"name": "test2-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"type": "crossProduct",
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"userId": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`job .getAll() : gets all available jobs 2`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest2",
|
||||
"paramsVector": Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"type": "set",
|
||||
"values": Array [
|
||||
Object {
|
||||
"id": "0342407f-9727-4f12-83c2-9d0c458916c2",
|
||||
"name": "test2-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"type": "crossProduct",
|
||||
},
|
||||
]
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"userId": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`job .set() : fails trying to set a job without job.id 1`] = `[JsonRpcError: invalid parameters]`;
|
||||
|
||||
exports[`job .set() : sets a job 1`] = `
|
||||
Object {
|
||||
"id": Any<String>,
|
||||
"key": "snapshot",
|
||||
"method": "vm.clone",
|
||||
"name": "jobTest",
|
||||
@@ -127,5 +137,6 @@ Object {
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
"userId": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { difference, keyBy, omit } from "lodash";
|
||||
import { difference, keyBy } from "lodash";
|
||||
|
||||
import config from "../_config";
|
||||
import xo, { testWithOtherConnection } from "../_xoConnection";
|
||||
@@ -47,7 +47,10 @@ describe("job", () => {
|
||||
expect(typeof id).toBe("string");
|
||||
|
||||
const job = await xo.call("job.get", { id });
|
||||
expect(omit(job, "id", "userId")).toMatchSnapshot();
|
||||
expect(job).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
expect(job.userId).toBe(userId);
|
||||
await xo.call("job.delete", { id });
|
||||
});
|
||||
@@ -89,10 +92,14 @@ describe("job", () => {
|
||||
let jobs = await xo.call("job.getAll");
|
||||
expect(Array.isArray(jobs)).toBe(true);
|
||||
jobs = keyBy(jobs, "id");
|
||||
expect([
|
||||
omit(jobs[jobId1], "id", "userId"),
|
||||
omit(jobs[jobId2], "id", "userId"),
|
||||
]).toMatchSnapshot();
|
||||
expect(jobs[jobId1]).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
expect(jobs[jobId2]).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,7 +107,10 @@ describe("job", () => {
|
||||
it("gets an existing job", async () => {
|
||||
const id = await xo.createTempJob(defaultJob);
|
||||
const job = await xo.call("job.get", { id });
|
||||
expect(omit(job, "id", "userId")).toMatchSnapshot();
|
||||
expect(job).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
});
|
||||
|
||||
it("fails trying to get a job with a non existent id", async () => {
|
||||
@@ -136,9 +146,10 @@ describe("job", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(
|
||||
omit(await xo.call("job.get", { id }), "id", "userId")
|
||||
).toMatchSnapshot();
|
||||
expect(await xo.call("job.get", { id })).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
userId: expect.any(String),
|
||||
});
|
||||
});
|
||||
|
||||
it("fails trying to set a job without job.id", async () => {
|
||||
|
||||
@@ -14,6 +14,7 @@ exports[`user .create() : creates a user with permission 1`] = `
|
||||
Object {
|
||||
"email": "wayne2@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
}
|
||||
@@ -23,6 +24,7 @@ exports[`user .create() : creates a user without permission 1`] = `
|
||||
Object {
|
||||
"email": "wayne1@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"preferences": Object {},
|
||||
}
|
||||
`;
|
||||
@@ -38,20 +40,23 @@ exports[`user .delete() : fails trying to delete a user with a nonexistent user
|
||||
exports[`user .delete() : fails trying to delete itself 1`] = `[JsonRpcError: a user cannot delete itself]`;
|
||||
|
||||
exports[`user .getAll() : gets all the users created 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"email": "wayne4@vates.fr",
|
||||
"groups": Array [],
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
},
|
||||
Object {
|
||||
"email": "wayne5@vates.fr",
|
||||
"groups": Array [],
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
},
|
||||
]
|
||||
Object {
|
||||
"email": "wayne4@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`user .getAll() : gets all the users created 2`] = `
|
||||
Object {
|
||||
"email": "wayne5@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`user .set() : fails trying to set a password with a non admin user connection 1`] = `[JsonRpcError: this properties can only changed by an administrator]`;
|
||||
@@ -70,6 +75,7 @@ exports[`user .set() : sets a password 1`] = `
|
||||
Object {
|
||||
"email": "wayne3@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "none",
|
||||
"preferences": Object {},
|
||||
}
|
||||
@@ -79,6 +85,7 @@ exports[`user .set() : sets a permission 1`] = `
|
||||
Object {
|
||||
"email": "wayne3@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "user",
|
||||
"preferences": Object {},
|
||||
}
|
||||
@@ -88,6 +95,7 @@ exports[`user .set() : sets a preference 1`] = `
|
||||
Object {
|
||||
"email": "wayne3@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "none",
|
||||
"preferences": Object {
|
||||
"filters": Object {
|
||||
@@ -103,6 +111,7 @@ exports[`user .set() : sets an email 1`] = `
|
||||
Object {
|
||||
"email": "wayne_modified@vates.fr",
|
||||
"groups": Array [],
|
||||
"id": Any<String>,
|
||||
"permission": "none",
|
||||
"preferences": Object {},
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { forOwn, keyBy, omit } from "lodash";
|
||||
import { forOwn, keyBy } from "lodash";
|
||||
|
||||
import xo, { testConnection, testWithOtherConnection } from "../_xoConnection";
|
||||
|
||||
@@ -37,7 +37,9 @@ describe("user", () => {
|
||||
async data => {
|
||||
const userId = await xo.createUser(data);
|
||||
expect(typeof userId).toBe("string");
|
||||
expect(omit(await xo.getUser(userId), "id")).toMatchSnapshot();
|
||||
expect(await xo.getUser(userId)).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
});
|
||||
await testConnection({
|
||||
credentials: {
|
||||
email: data.email,
|
||||
@@ -134,10 +136,8 @@ describe("user", () => {
|
||||
let users = await xo.call("user.getAll");
|
||||
expect(Array.isArray(users)).toBe(true);
|
||||
users = keyBy(users, "id");
|
||||
expect([
|
||||
omit(users[userId1], "id"),
|
||||
omit(users[userId2], "id"),
|
||||
]).toMatchSnapshot();
|
||||
expect(users[userId1]).toMatchSnapshot({ id: expect.any(String) });
|
||||
expect(users[userId2]).toMatchSnapshot({ id: expect.any(String) });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -160,7 +160,9 @@ describe("user", () => {
|
||||
async data => {
|
||||
data.id = await xo.createUser(SIMPLE_USER);
|
||||
expect(await xo.call("user.set", data)).toBe(true);
|
||||
expect(omit(await xo.getUser(data.id), "id")).toMatchSnapshot();
|
||||
expect(await xo.getUser(data.id)).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
});
|
||||
|
||||
await testConnection({
|
||||
credentials: {
|
||||
|
||||
Reference in New Issue
Block a user