Skip to content

Commit 97e3d7a

Browse files
andypolsjescalada
andauthored
Update test/db/file/repo.test.js
Co-authored-by: Juan Escalada <97265671+jescalada@users.noreply.github.com> Signed-off-by: Andy Pols <andy@pols.co.uk>
1 parent d652f9d commit 97e3d7a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/db/file/repo.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,39 @@ describe('File DB', () => {
5656
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy.git'}))).to.be.true;
5757
expect(result).to.equal(repoData);
5858
});
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;
72+
});
73+
74+
it('should return null if the repo is not found', async () => {
75+
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, null));
76+
77+
const result = await repoModule.getRepoByUrl('https://github.com/finos/missing-repo.git');
78+
expect(result).to.be.null;
79+
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/missing-repo.git' })),
80+
).to.be.true;
81+
});
82+
83+
it('should reject if the database returns an error', async () => {
84+
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(new Error('DB error')));
85+
86+
try {
87+
await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
88+
expect.fail('Expected promise to be rejected');
89+
} catch (err) {
90+
expect(err.message).to.equal('DB error');
91+
}
92+
});
5993
});
6094
});

0 commit comments

Comments
 (0)