Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/src/blocked-repository-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
const expect = chai.expect;
9
import { suite, test, timeout } from "@testdeck/mocha";
10
11
import { testContainer } from "./test-container";
12
import { TypeORMBlockedRepositoryDBImpl } from "./typeorm/blocked-repository-db-impl";
13
import { TypeORM } from "./typeorm/typeorm";
14
import { resetDB } from "./test/reset-db";
15
16
@suite
17
class BlockedRepositoryDBSpec {
18
blockedRepositoryDb = testContainer.get<TypeORMBlockedRepositoryDBImpl>(TypeORMBlockedRepositoryDBImpl);
19
20
async before() {
21
await this.wipeRepo();
22
}
23
24
async after() {
25
await this.wipeRepo();
26
}
27
28
@test(timeout(10000))
29
public async canCreateABlockedRepository() {
30
const blockedRepository = await this.blockedRepositoryDb.createBlockedRepository(
31
"github.com/bob/some-repo",
32
true,
33
false,
34
);
35
expect(blockedRepository.urlRegexp).eq("github.com/bob/some-repo");
36
expect(blockedRepository.blockUser).eq(true);
37
}
38
39
@test(timeout(10000))
40
public async checkRepositoryIsBlocked() {
41
await this.blockedRepositoryDb.createBlockedRepository("github.com/bob/.*", true, false);
42
43
const blockedRepository = await this.blockedRepositoryDb.findBlockedRepositoryByURL("github.com/bob/some-repo");
44
45
expect(blockedRepository).not.undefined;
46
expect(blockedRepository?.urlRegexp).to.eq("github.com/bob/.*");
47
expect(blockedRepository?.blockUser).to.eq(true);
48
}
49
50
@test(timeout(10000))
51
public async checkRepositoryIsNotBlocked() {
52
await this.blockedRepositoryDb.createBlockedRepository("github.com/bob/.*", true, false);
53
54
const blockedRepository = await this.blockedRepositoryDb.findBlockedRepositoryByURL(
55
"github.com/alice/some-repo",
56
);
57
58
expect(blockedRepository).undefined;
59
}
60
61
@test(timeout(10000))
62
public async canFindAllRepositoriesWithoutSearchTerm() {
63
await this.blockedRepositoryDb.createBlockedRepository("github.com/bob/.*", true, false);
64
await this.blockedRepositoryDb.createBlockedRepository("github.com/alice/.*", true, false);
65
66
const blockedRepositories = await this.blockedRepositoryDb.findAllBlockedRepositories(0, 1, "id", "ASC");
67
68
expect(blockedRepositories.total).eq(2);
69
}
70
71
@test(timeout(10000))
72
public async canFindAllRepositoriesWithSearchTerm() {
73
await this.blockedRepositoryDb.createBlockedRepository("github.com/bob/.*", true, false);
74
await this.blockedRepositoryDb.createBlockedRepository("github.com/alice/.*", true, false);
75
76
const blockedRepositories = await this.blockedRepositoryDb.findAllBlockedRepositories(0, 1, "id", "ASC", "bob");
77
78
expect(blockedRepositories.total).eq(1);
79
}
80
81
async wipeRepo() {
82
const typeorm = testContainer.get<TypeORM>(TypeORM);
83
await resetDB(typeorm);
84
}
85
}
86
87
module.exports = new BlockedRepositoryDBSpec();
88
89