-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-helpers.js
160 lines (153 loc) · 3.42 KB
/
test-helpers.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
function makeUsersArray() {
return [
{
id: 1,
user_name: 'test-user-1',
full_name: 'Test user 1',
password: 'Password1',
date_created: '2029-01-22T16:28:32.615Z',
date_modified: '2029-01-22T16:28:37.615Z',
},
{
id: 2,
user_name: 'test-user-2',
full_name: 'Test user 2',
password: 'Password2',
date_created: '2029-01-22T16:28:32.615Z',
date_modified: '2029-01-22T16:28:37.615Z',
},
{
id: 3,
user_name: 'test-user-3',
full_name: 'Test user 3',
password: 'Password3',
date_created: '2029-01-22T16:28:32.615Z',
date_modified: '2029-01-22T16:28:37.615Z',
},
{
id: 4,
user_name: 'test-user-4',
full_name: 'Test user 4',
password: 'Password4',
date_created: '2029-01-22T16:28:32.615Z',
date_modified: '2029-01-22T16:28:37.615Z',
},
];
}
function makeProjectsArray(users) {
return [
{
title: 'test1',
user_id: users[0].id,
date_created: '2029-01-22T16:28:32.615Z',
},
{
title: 'test2',
user_id: users[1].id,
date_created: '2029-01-22T16:28:32.615Z',
},
{
title: 'test3',
user_id: users[2].id,
date_created: '2029-01-22T16:28:32.615Z',
},
{
title: 'test4',
user_id: users[3].id,
date_created: '2029-01-22T16:28:32.615Z',
},
];
}
function makeListsArray() {
return [
{
project_id: 1,
title: 'test1',
date_created: '2029-01-22T16:28:32.615Z',
},
{
project_id: 1,
title: 'test1',
date_created: '2029-01-22T16:28:32.615Z',
},
{
project_id: 1,
title: 'test1',
date_created: '2029-01-22T16:28:32.615Z',
},
{
project_id: 1,
title: 'test1',
date_created: '2029-01-22T16:28:32.615Z',
},
];
}
function makeCardsArray() {
return [
{
list_id: 1,
content: 'card 1',
date_created: '2029-01-22T16:28:32.615Z',
},
{
list_id: 2,
content: 'card 2',
date_created: '2029-01-22T16:28:32.615Z',
},
{
list_id: 1,
content: 'card 3',
date_created: '2029-01-22T16:28:32.615Z',
},
{
list_id: 2,
content: 'card 4',
date_created: '2029-01-22T16:28:32.615Z',
},
];
}
function makeFixtures() {
const testUsers = makeUsersArray();
const testProjects = makeProjectsArray(testUsers);
const testLists = makeListsArray();
const testCards = makeCardsArray();
return { testUsers, testProjects, testLists, testCards };
}
//WILL BE UTILIZED IN THE FUTURE
// function makeAuthHeader(user, secret = process.env.JWT_SECRET) {
// const token = jwt.sign({ user_id: user.id }, secret, {
// subject: user.user_name,
// algorithm: 'HS256',
// });
// return `Bearer ${token}`;
// }
function cleanTables(db) {
return db.raw(
`TRUNCATE
gtpro_users,
gtpro_projects,
gtpro_lists,
gtpro_cards
RESTART IDENTITY CASCADE`
);
}
//WILL BE UTILIZED IN THE FUTURE
// function seedUsers(db, users) {
// // const preppedUsers = users.map((user) => ({
// // ...user,
// // password: bcrypt.hashSync(user.password, 1),
// // }));
// return db
// .insert(users)
// .into('itav_users')
// .returning('*')
// .then(([user]) => user);
// }
module.exports = {
makeUsersArray,
makeListsArray,
makeProjectsArray,
makeCardsArray,
makeFixtures,
cleanTables,
};