-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_testCommon.js
104 lines (90 loc) · 2.34 KB
/
_testCommon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use strict";
const db = require("../db.js");
const User = require("../models/user");
const Company = require("../models/company");
const Job = require("../models/job");
const { createToken } = require("../helpers/tokens");
const testJobIds = [];
async function commonBeforeAll() {
// noinspection SqlWithoutWhere
await db.query("DELETE FROM users");
// noinspection SqlWithoutWhere
await db.query("DELETE FROM companies");
await Company.create(
{
handle: "c1",
name: "C1",
numEmployees: 1,
description: "Desc1",
logoUrl: "http://c1.img",
});
await Company.create(
{
handle: "c2",
name: "C2",
numEmployees: 2,
description: "Desc2",
logoUrl: "http://c2.img",
});
await Company.create(
{
handle: "c3",
name: "C3",
numEmployees: 3,
description: "Desc3",
logoUrl: "http://c3.img",
});
testJobIds[0] = (await Job.create(
{ title: "J1", salary: 1, equity: "0.1", companyHandle: "c1" })).id;
testJobIds[1] = (await Job.create(
{ title: "J2", salary: 2, equity: "0.2", companyHandle: "c1" })).id;
testJobIds[2] = (await Job.create(
{ title: "J3", salary: 3, /* equity null */ companyHandle: "c1" })).id;
await User.register({
username: "u1",
firstName: "U1F",
lastName: "U1L",
email: "[email protected]",
password: "password1",
isAdmin: false,
});
await User.register({
username: "u2",
firstName: "U2F",
lastName: "U2L",
email: "[email protected]",
password: "password2",
isAdmin: false,
});
await User.register({
username: "u3",
firstName: "U3F",
lastName: "U3L",
email: "[email protected]",
password: "password3",
isAdmin: false,
});
await User.applyToJob("u1", testJobIds[0]);
}
async function commonBeforeEach() {
await db.query("BEGIN");
}
async function commonAfterEach() {
await db.query("ROLLBACK");
}
async function commonAfterAll() {
await db.end();
}
const u1Token = createToken({ username: "u1", isAdmin: false });
const u2Token = createToken({ username: "u2", isAdmin: false });
const adminToken = createToken({ username: "admin", isAdmin: true });
module.exports = {
commonBeforeAll,
commonBeforeEach,
commonAfterEach,
commonAfterAll,
testJobIds,
u1Token,
u2Token,
adminToken,
};