-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathapi-resync-failed-tasks.test.ts
96 lines (77 loc) · 2.4 KB
/
api-resync-failed-tasks.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
95
96
import express, { Application, NextFunction, Request, Response } from "express";
import { mocked } from "jest-mock";
import { booleanFlag } from "~/src/config/feature-flags";
import { getLogger } from "~/src/config/logger";
import { ApiRouter } from "./api-router";
import supertest from "supertest";
import { Installation } from "~/src/models/installation";
import { Subscription, SyncStatus } from "~/src/models/subscription";
jest.mock("config/feature-flags");
jest.mock("~/src/sync/sync-utils");
const mockBooleanFlag = mocked(booleanFlag);
const createApp = () => {
const app = express();
app.use((req: Request, _: Response, next: NextFunction) => {
req.log = getLogger("test");
next();
});
app.use("/api", ApiRouter);
return app;
};
describe("api-resync-failed-tasks", () => {
let app: Application;
let subscription: Subscription;
const gitHubInstallationId = 1234;
beforeEach(async () => {
await Installation.create({
gitHubInstallationId,
jiraHost,
encryptedSharedSecret: "secret",
clientKey: "client-key"
});
subscription = await Subscription.create({
gitHubInstallationId,
jiraHost,
jiraClientKey: "client-key",
syncStatus: SyncStatus.PENDING
});
mockBooleanFlag.mockResolvedValue(true);
});
it("should return 400 if slauth header is missing", async () => {
app = createApp();
await supertest(app)
.post(`/api/resync-failed-tasks`)
.then((res) => {
expect(res.status).toBe(401);
});
});
it("should return error message if input is empty", async () => {
app = createApp();
await supertest(app)
.post(`/api/resync-failed-tasks`)
.set("X-Slauth-Mechanism", "asap")
.then((res) => {
expect(res.text).toContain("Please provide at least one subscription id");
});
});
it("should return error message if target task is empty", async () => {
app = createApp();
await supertest(app)
.post(`/api/resync-failed-tasks`)
.send({ subscriptionsIds: [123] })
.set("X-Slauth-Mechanism", "asap")
.then((res) => {
expect(res.text).toContain("Please provide target type");
});
});
it("should resync failed tasks", async () => {
app = createApp();
await supertest(app)
.post(`/api/resync-failed-tasks`)
.send({ subscriptionsIds: [subscription.id], targetTasks: ["dependabotAlert"] })
.set("X-Slauth-Mechanism", "asap")
.then((res) => {
expect(res.text).toContain("Triggered backfill successfully");
});
});
});