-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathDeployQueueServer.test.ts
executable file
·94 lines (87 loc) · 3.45 KB
/
DeployQueueServer.test.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
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
#! /usr/bin/env jest
import fs from "fs-extra"
import { DeployQueueServer } from "./DeployQueueServer.js"
import {
DEPLOY_QUEUE_FILE_PATH,
DEPLOY_PENDING_FILE_PATH,
} from "../settings/serverSettings.js"
import { jest } from "@jest/globals"
describe("parseQueueContent", () => {
const server = new DeployQueueServer()
it("parses newline delimited JSON objects", async () => {
const output = server.parseQueueContent(
[
`{"authorName": "Tester", "message": "Updated chart test-chart-please-ignore"}`,
`{"authorName": "Tester", "message": "something one"}`,
``, // empty line will be ignored
`invalid json`, // invalid json will be ignored
`{"authorName": "Tester", "message": "something two"}`,
`{"authorName": "Tester", "message": "lightning deploy", "slug": "article-lightning-deploy"}`, // the presence of a slug makes the change eligible to a lightning deploy
].join("\n")
)
expect(output[0].authorName).toEqual("Tester")
expect(output[0].message).toEqual(
"Updated chart test-chart-please-ignore"
)
expect(output[1].message).toEqual("something one")
expect(output[2].message).toEqual("something two")
expect(output[3].slug).toEqual("article-lightning-deploy")
})
})
// todo: pretty sure Spyon is an antipattern. Create a deploy class that takes an interface with the subset of fs instead, and then can pass
// a tiny mock FS for testing.
describe("getDeploys", () => {
const server = new DeployQueueServer()
it("is empty when nothing is in the queues", async () => {
jest.spyOn(fs, "readFile").mockImplementation(
(async (): Promise<string> => {
return ``
}) as any
)
expect(await server.getDeploys()).toEqual([])
})
it("parses queued deploy file", async () => {
jest.spyOn(fs, "readFile").mockImplementation((async (
path: string
): Promise<string> => {
if (path === DEPLOY_QUEUE_FILE_PATH)
return [`{"message": "test1"}`, `{"message": "test2"}`].join(
"\n"
)
if (path === DEPLOY_PENDING_FILE_PATH) return ``
return ``
}) as any)
expect(await server.getDeploys()).toEqual([
{
status: "queued",
changes: [{ message: "test2" }, { message: "test1" }],
},
])
})
it("parses pending deploy file", async () => {
jest.spyOn(fs, "pathExists").mockImplementation(async () => true)
jest.spyOn(fs, "readFile").mockImplementation((async (
path: string
): Promise<string> => {
if (path === DEPLOY_QUEUE_FILE_PATH)
return [`{"message": "test1"}`, `{"message": "test2"}`].join(
"\n"
)
if (path === DEPLOY_PENDING_FILE_PATH)
return [`{"message": "test3"}`, `{"message": "test4"}`].join(
"\n"
)
return ``
}) as any)
expect(await server.getDeploys()).toEqual([
{
status: "queued",
changes: [{ message: "test2" }, { message: "test1" }],
},
{
status: "pending",
changes: [{ message: "test4" }, { message: "test3" }],
},
])
})
})