-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
52 lines (48 loc) · 1.61 KB
/
index.spec.ts
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
import * as bscUtil from "./utils/broadsign_control"
import * as csvUtil from "./utils/csv"
import { runPuller } from "./index"
jest.mock("./utils/broadsign_control")
jest.mock("./utils/csv")
const TEST_ENV = {BSC_BASE_URL:"http://baseurl.com", BSC_TOKEN:"bsctoken"}
const originalEnv = process.env;
process.env = {...process.env, ...TEST_ENV}
const mockPullDayPartDataFromBSC = jest.spyOn(bscUtil, "pullDayPartDataFromBSC")
jest.spyOn(csvUtil, "saveDataToLocalCSVFile")
mockPullDayPartDataFromBSC.mockReturnValue(Promise.resolve(getMockDaypartList()))
describe('Testing entire data pulling flow', () => {
afterAll(done=>{
process.env = originalEnv;
jest.resetAllMocks()
done();
})
test('call once to pullDayPartDataFromBSC, saveDataToLocalCSVFile', async() => {
await runPuller();
expect(bscUtil.pullDayPartDataFromBSC).toHaveBeenCalledTimes(1);
expect(csvUtil.saveDataToLocalCSVFile).toHaveBeenCalledTimes(1);
});
test('saveDataToLocalCSVFile has been called with daypart List written by pullDayPartDataFromBSC', async() => {
await runPuller();
expect(csvUtil.saveDataToLocalCSVFile).toHaveBeenCalledWith(getMockDaypartList())
});
});
function getMockDaypartList():Daypart[] {
return [
{
"active": true,
"day_mask": 0,
"domain_id": 0,
"end_date": "string",
"end_time": "string",
"id": 0,
"parent_id": 0,
"impressions_per_hour": 0,
"minute_mask": "string",
"name": "string",
"start_date": "string",
"start_time": "string",
"virtual_end_date": "string",
"virtual_start_date": "string",
"weight": 0
}
]
}