-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathshift.test.js
More file actions
136 lines (118 loc) · 6.22 KB
/
shift.test.js
File metadata and controls
136 lines (118 loc) · 6.22 KB
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
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const { resetDatabaseContent } = require('../utilities/resetDatabaseContent.js');
const request = require('supertest');
const { server } = require('../../lib/application');
const { expect } = require('chai');
const { shiftService } = require('../../lib/server/services/shift/ShiftService.js');
const { createLog } = require('../../lib/server/services/log/createLog.js');
module.exports = () => {
beforeEach(resetDatabaseContent);
describe('GET /api/shift-data', () => {
it('should successfully return the data related to the current user\'s ECS shift', async () => {
// Create some logs for the shift
const logIds = [];
const currentShift = shiftService.getUserPendingShiftOrFail();
const defaultLogData = {
title: 'Title',
text: 'Text',
subtype: 'comment',
origin: 'process',
userId: 2,
createdAt: currentShift.start,
};
// Not kept : not the good tags
await createLog(defaultLogData, [], ['EoS'], [], [], []);
logIds.push(await createLog(defaultLogData, [], ['ECS Shifter', 'EoS'], [], [], []));
// Keep the 1 log ids as it has good tags for 'ECS Shifter'
logIds.push(await createLog(defaultLogData, [], ['ECS Shifter'], [], [], []));
const response = await request(server).get('/api/shift-data?shiftType=ECS');
expect(response.status).to.equal(200);
expect(response.body.data).to.be.an('object');
expect(response.body.data.issuesLogs).to.lengthOf(1);
expect(response.body.data.issuesLogs.every(({ id }) => logIds.includes(id))).to.be.true;
});
it('should successfully return the data related to the current user\'s QC/PDP shift', async () => {
// Create some logs for the shift
const logIds = [];
const currentShift = shiftService.getUserPendingShiftOrFail();
const defaultLogData = {
title: 'Title',
text: 'Text',
subtype: 'comment',
origin: 'process',
userId: 2,
createdAt: currentShift.start,
};
// Not kept : not the good tags
await createLog(defaultLogData, [], ['EoS'], [], [], []);
logIds.push(await createLog(defaultLogData, [], ['QC/PDP Shifter', 'EoS'], [], [], []));
// Keep the 1 log ids as it has good tags for 'QC/PDP Shifter'
logIds.push(await createLog(defaultLogData, [], ['QC/PDP Shifter'], [], [], []));
const response = await request(server).get('/api/shift-data?shiftType=QC/PDP');
expect(response.status).to.equal(200);
expect(response.body.data).to.be.an('object');
expect(response.body.data.issuesLogs).to.lengthOf(1);
expect(response.body.data.issuesLogs.every(({ id }) => logIds.includes(id))).to.be.true;
});
it('should successfully return the data related to the current user\'s SLIMOS shift', async () => {
// Create some logs for the shift
const logIds = [];
const currentShift = shiftService.getUserPendingShiftOrFail();
const defaultLogData = {
title: 'Title',
text: 'Text',
subtype: 'comment',
origin: 'process',
userId: 2,
createdAt: currentShift.start,
};
// Not kept : not the good tags
await createLog(defaultLogData, [], ['EoS'], [], [], []);
logIds.push(await createLog(defaultLogData, [], ['SLIMOS', 'EoS'], [], [], []));
// Keep the 1 log ids as it has good tags for 'SLIMOS'
logIds.push(await createLog(defaultLogData, [], ['SLIMOS'], [], [], []));
const response = await request(server).get('/api/shift-data?shiftType=SLIMOS');
expect(response.status).to.equal(200);
expect(response.body.data).to.be.an('object');
expect(response.body.data.issuesLogs).to.lengthOf(1);
expect(response.body.data.issuesLogs.every(({ id }) => logIds.includes(id))).to.be.true;
});
it('should successfully return the data related to the current user\'s Shift Leader shift', async () => {
// Create some logs for the shift
const logIds = [];
const currentShift = shiftService.getUserPendingShiftOrFail();
const defaultLogData = {
title: 'Title',
text: 'Text',
subtype: 'comment',
origin: 'process',
userId: 2,
createdAt: currentShift.start,
};
// Not kept : not the good tags
await createLog(defaultLogData, [], ['EoS'], [], [], []);
await createLog(defaultLogData, [], ['Shift Leader', 'EoS'], [], [], []);
// Keep the 4 log ids as it has good tags for 'Shift Leader'
logIds.push(await createLog(defaultLogData, [], ['Shift Leader'], [], [], []));
logIds.push(await createLog(defaultLogData, [], ['ECS Shifter'], [], [], []));
logIds.push(await createLog(defaultLogData, [], ['DCS Shifter'], [], [], []));
logIds.push(await createLog(defaultLogData, [], ['QC/PDP Shifter'], [], [], []));
const response = await request(server).get('/api/shift-data?shiftType=SL');
expect(response.status).to.equal(200);
expect(response.body.data).to.be.an('object');
expect(response.body.data.issuesLogs).to.lengthOf(4);
expect(response.body.data.issuesLogs.every(({ id }) => logIds.includes(id))).to.be.true;
});
});
};