Skip to content

Commit 0efc40d

Browse files
committed
chore: update tests
1 parent 2be29e8 commit 0efc40d

File tree

4 files changed

+21
-69
lines changed

4 files changed

+21
-69
lines changed

src/proxy/processors/push-action/checkRepoInAuthorisedList.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const exec = async (req: any, action: Action): Promise<Action> => {
77

88
const found = (await getRepoByUrl(action.url)) !== null;
99
if (found) {
10-
step.log(`repo ${action.repo} is in the authorisedList`);
10+
step.log(`repo ${action.url} is in the authorisedList`);
1111
} else {
1212
step.error = true;
13-
step.log(`repo ${action.repo} is not in the authorised whitelist, ending`);
14-
step.setError(`Rejecting repo ${action.repo} not in the authorised whitelist`);
13+
step.log(`repo ${action.url} is not in the authorised whitelist, ending`);
14+
step.setError(`Rejecting repo ${action.url} not in the authorised whitelist`);
1515
}
1616

1717
action.addStep(step);

test/db/file/repo.test.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('File DB', () => {
2424
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
2525

2626
const result = await repoModule.getRepo('Sample');
27-
expect(result).to.equal(repoData);
27+
expect(result).to.deep.equal(repoData);
2828
});
2929
});
3030

@@ -39,7 +39,7 @@ describe('File DB', () => {
3939
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
4040

4141
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
42-
expect(result).to.equal(repoData);
42+
expect(result).to.deep.equal(repoData);
4343
});
4444

4545
it('should get the repo using the url, stripping off the .git', async () => {
@@ -53,36 +53,29 @@ describe('File DB', () => {
5353

5454
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
5555

56-
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy.git'}))).to.be.true;
57-
expect(result).to.equal(repoData);
58-
});
59-
60-
it('should get the repo using the url, ignoring the case', async () => {
61-
const repoData = {
62-
name: 'sample',
63-
users: { canPush: [] },
64-
url: 'https://github.com/finos/git-proxy.git',
65-
};
66-
67-
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
68-
69-
const result = await repoModule.getRepoByUrl('https://github.com/Finos/Git-Proxy.git');
70-
expect(result).to.equal(repoData);
71-
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy.git' }))).to.be.true;
56+
expect(
57+
repoModule.db.findOne.calledWith(
58+
sinon.match({ url: 'https://github.com/finos/git-proxy.git' }),
59+
),
60+
).to.be.true;
61+
expect(result).to.deep.equal(repoData);
7262
});
7363

7464
it('should return null if the repo is not found', async () => {
7565
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, null));
7666

7767
const result = await repoModule.getRepoByUrl('https://github.com/finos/missing-repo.git');
7868
expect(result).to.be.null;
79-
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/missing-repo.git' })),
69+
expect(
70+
repoModule.db.findOne.calledWith(
71+
sinon.match({ url: 'https://github.com/finos/missing-repo.git' }),
72+
),
8073
).to.be.true;
8174
});
8275

8376
it('should reject if the database returns an error', async () => {
8477
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(new Error('DB error')));
85-
78+
8679
try {
8780
await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
8881
expect.fail('Expected promise to be rejected');

test/db/mongo/repo.test.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('MongoDB', () => {
2727
repoCollection.findOne.resolves(repoData);
2828

2929
const result = await getRepo('Sample');
30-
expect(result).to.equal(repoData);
30+
expect(result).to.deep.equal(repoData);
3131
expect(connectionStub.calledWith('repos')).to.be.true;
3232
expect(repoCollection.findOne.calledWith({ name: { $eq: 'sample' } })).to.be.true;
3333
});
@@ -43,26 +43,12 @@ describe('MongoDB', () => {
4343
repoCollection.findOne.resolves(repoData);
4444

4545
const result = await getRepoByUrl('https://github.com/finos/git-proxy.git');
46-
expect(result).to.equal(repoData);
46+
expect(result).to.deep.equal(repoData);
4747
expect(connectionStub.calledWith('repos')).to.be.true;
4848
expect(
49-
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy.git' } }),
50-
).to.be.true;
51-
});
52-
53-
it('should get the repo using the url, ignoring the case', async () => {
54-
const repoData = {
55-
name: 'sample',
56-
users: { canPush: [] },
57-
url: 'https://github.com/finos/git-proxy.git',
58-
};
59-
repoCollection.findOne.resolves(repoData);
60-
61-
const result = await getRepoByUrl('https://github.com/Finos/Git-Proxy.git');
62-
expect(result).to.equal(repoData);
63-
expect(connectionStub.calledWith('repos')).to.be.true;
64-
expect(
65-
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy.git' } }),
49+
repoCollection.findOne.calledWith({
50+
url: { $eq: 'https://github.com/finos/git-proxy.git' },
51+
}),
6652
).to.be.true;
6753
});
6854
});

test/testCheckRepoInAuthList.test.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)