Path: blob/main/components/gitpod-db/src/webhook-event-db.spec.db.ts
2497 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import * as chai from "chai";7import { suite, test, timeout } from "@testdeck/mocha";8import { testContainer } from "./test-container";9import { TypeORM } from "./typeorm/typeorm";10import { WebhookEventDB } from "./webhook-event-db";11import { resetDB } from "./test/reset-db";12const expect = chai.expect;1314@suite15@timeout(5000)16export class WebhookEventDBSpec {17typeORM = testContainer.get<TypeORM>(TypeORM);18db = testContainer.get<WebhookEventDB>(WebhookEventDB);1920async before() {21await this.clear();22}2324async after() {25await this.clear();26}2728protected async clear() {29await resetDB(this.typeORM);30}3132@test public async testSafeUpdate() {33const event = await this.db.createEvent({34rawEvent: "payload as string",35status: "received",36type: "push",37});38const cloneUrl = "http://gitlab.local/project/repo";39await this.db.updateEvent(event.id, {40status: "ignored",41rawEvent: "should not be overriden",42type: "should not be overriden",43cloneUrl,44});4546const updated = (await this.db.findByCloneUrl(cloneUrl))[0];47expect(updated, "should be found").to.be.not.undefined;48expect(updated.status, "status should be updated").to.equal("ignored");49expect(updated.type, "type should not be updated").to.equal("push");50expect(updated.rawEvent, "rawEvent should not be updated").to.equal("payload as string");51}5253@test public async testDeleteOldEvents() {54const cloneUrl = "http://gitlab.local/project/repo";55await this.db.createEvent({56rawEvent: "payload as string",57status: "received",58type: "push",59cloneUrl,60});6162await this.db.deleteOldEvents(0, 1);6364const events = await this.db.findByCloneUrl(cloneUrl);65expect(events.length).to.be.eq(0);66}67}6869module.exports = WebhookEventDBSpec;707172