@@ -4,6 +4,7 @@ pool = 'lab3'
|
||||
pvVm = 'xo-test-pv'
|
||||
vmToMigrate = 'souad'
|
||||
xoServerUrl = 'localhost:9000'
|
||||
vmIdXoTest = 'ceabe44c-f04d-6674-5599-bfd7b7e298ba'
|
||||
|
||||
# powerOnMode has to be not empty
|
||||
host1 = 'lab1'
|
||||
|
||||
@@ -5,6 +5,7 @@ export default class XoWithTestHelpers extends Xo {
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
this.userIds = [];
|
||||
this.jobIds = [];
|
||||
}
|
||||
|
||||
async createUser(params) {
|
||||
@@ -25,4 +26,19 @@ export default class XoWithTestHelpers extends Xo {
|
||||
async getUser(id) {
|
||||
return find(await super.call("user.getAll"), { id });
|
||||
}
|
||||
|
||||
async createJob(params) {
|
||||
const jobId = await super.call("job.create", { job: params });
|
||||
this.jobIds.push(jobId);
|
||||
return jobId;
|
||||
}
|
||||
|
||||
async deleteAllJobs() {
|
||||
await Promise.all(
|
||||
this.jobIds.map(id =>
|
||||
super.call("job.delete", { id }).catch(error => console.error(error))
|
||||
)
|
||||
);
|
||||
this.jobIds.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
27
src/job/__snapshots__/job.spec.js.snap
Normal file
27
src/job/__snapshots__/job.spec.js.snap
Normal file
@@ -0,0 +1,27 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`job .create() : creates a new job 1`] = `
|
||||
Object {
|
||||
"key": "snapshot",
|
||||
"method": "vm.snapshot",
|
||||
"name": "jobTest",
|
||||
"paramsVector": Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"type": "set",
|
||||
"values": Array [
|
||||
Object {
|
||||
"id": "ceabe44c-f04d-6674-5599-bfd7b7e298ba",
|
||||
"name": "test-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
"type": "crossProduct",
|
||||
},
|
||||
"timeout": 2000,
|
||||
"type": "call",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`job .create() : fails trying to create a job without job params 1`] = `[JsonRpcError: invalid parameters]`;
|
||||
66
src/job/job.spec.js
Normal file
66
src/job/job.spec.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
import { omit } from "lodash";
|
||||
|
||||
import config from "../_config";
|
||||
import { xo, testWithOtherConnection } from "../util";
|
||||
|
||||
const ADMIN_USER = {
|
||||
email: "admin2@admin.net",
|
||||
password: "admin",
|
||||
permission: "admin",
|
||||
};
|
||||
|
||||
describe("job", () => {
|
||||
let defaultJob;
|
||||
|
||||
beforeAll(() => {
|
||||
defaultJob = {
|
||||
name: "jobTest",
|
||||
timeout: 2000,
|
||||
type: "call",
|
||||
key: "snapshot",
|
||||
method: "vm.snapshot",
|
||||
paramsVector: {
|
||||
type: "crossProduct",
|
||||
items: [
|
||||
{
|
||||
type: "set",
|
||||
values: [
|
||||
{
|
||||
id: config.vmIdXoTest,
|
||||
name: "test-snapshot",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe(".create() :", () => {
|
||||
it("creates a new job", async () => {
|
||||
const userId = await xo.createUser(ADMIN_USER);
|
||||
const { email, password } = ADMIN_USER;
|
||||
await testWithOtherConnection({ email, password }, async xo => {
|
||||
const id = await xo.createJob(defaultJob);
|
||||
expect(typeof id).toBe("string");
|
||||
|
||||
const job = await xo.call("job.get", { id });
|
||||
expect(omit(job, "id", "userId")).toMatchSnapshot();
|
||||
expect(job.userId).toBe(userId);
|
||||
});
|
||||
});
|
||||
|
||||
it("creates a job with a userId", async () => {
|
||||
const userId = await xo.createUser(ADMIN_USER);
|
||||
const id = await xo.createJob({ ...defaultJob, userId });
|
||||
const { userId: expectedUserId } = await xo.call("job.get", { id });
|
||||
expect(userId).toBe(expectedUserId);
|
||||
});
|
||||
|
||||
it("fails trying to create a job without job params", async () => {
|
||||
await expect(xo.createJob({})).rejects.toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -98,6 +98,7 @@ afterAll(async () => {
|
||||
});
|
||||
afterEach(async () => {
|
||||
await xo.deleteAllUsers();
|
||||
await xo.deleteAllJobs();
|
||||
});
|
||||
|
||||
// =================================================================
|
||||
|
||||
Reference in New Issue
Block a user