Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/src/webhook-event-db.spec.db.ts
2497 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import * as chai from "chai";
8
import { suite, test, timeout } from "@testdeck/mocha";
9
import { testContainer } from "./test-container";
10
import { TypeORM } from "./typeorm/typeorm";
11
import { WebhookEventDB } from "./webhook-event-db";
12
import { resetDB } from "./test/reset-db";
13
const expect = chai.expect;
14
15
@suite
16
@timeout(5000)
17
export class WebhookEventDBSpec {
18
typeORM = testContainer.get<TypeORM>(TypeORM);
19
db = testContainer.get<WebhookEventDB>(WebhookEventDB);
20
21
async before() {
22
await this.clear();
23
}
24
25
async after() {
26
await this.clear();
27
}
28
29
protected async clear() {
30
await resetDB(this.typeORM);
31
}
32
33
@test public async testSafeUpdate() {
34
const event = await this.db.createEvent({
35
rawEvent: "payload as string",
36
status: "received",
37
type: "push",
38
});
39
const cloneUrl = "http://gitlab.local/project/repo";
40
await this.db.updateEvent(event.id, {
41
status: "ignored",
42
rawEvent: "should not be overriden",
43
type: "should not be overriden",
44
cloneUrl,
45
});
46
47
const updated = (await this.db.findByCloneUrl(cloneUrl))[0];
48
expect(updated, "should be found").to.be.not.undefined;
49
expect(updated.status, "status should be updated").to.equal("ignored");
50
expect(updated.type, "type should not be updated").to.equal("push");
51
expect(updated.rawEvent, "rawEvent should not be updated").to.equal("payload as string");
52
}
53
54
@test public async testDeleteOldEvents() {
55
const cloneUrl = "http://gitlab.local/project/repo";
56
await this.db.createEvent({
57
rawEvent: "payload as string",
58
status: "received",
59
type: "push",
60
cloneUrl,
61
});
62
63
await this.db.deleteOldEvents(0, 1);
64
65
const events = await this.db.findByCloneUrl(cloneUrl);
66
expect(events.length).to.be.eq(0);
67
}
68
}
69
70
module.exports = WebhookEventDBSpec;
71
72