Avoid open interceptors in unit test

This commit is contained in:
Daz DeBoer 2026-01-28 13:07:32 -07:00
parent f29f5a9d7b
commit 49ec880f92
No known key found for this signature in database
2 changed files with 32 additions and 24 deletions

View File

@ -31,30 +31,6 @@ describe('short lived tokens', () => {
expect(develocityAccessCredentials?.raw()).toBe('host1=key1;host2=key2') expect(develocityAccessCredentials?.raw()).toBe('host1=key1;host2=key2')
}) })
it('get short lived token fails when cannot connect', async () => {
nock('http://localhost:3333')
.post('/api/auth/token')
.times(3)
.replyWithError({
message: 'connect ECONNREFUSED 127.0.0.1:3333',
code: 'ECONNREFUSED'
})
await expect(getToken('localhost=key0', false, ''))
.resolves
.toBeNull()
})
it('get short lived token is null when request fails', async () => {
nock('http://dev:3333')
.post('/api/auth/token')
.times(3)
.reply(500, 'Internal error')
expect.assertions(1)
await expect(getToken('dev=xyz', false, ''))
.resolves
.toBeNull()
})
it('get short lived token returns null when access key is empty', async () => { it('get short lived token returns null when access key is empty', async () => {
expect.assertions(1) expect.assertions(1)
await expect(getToken('', false, '')) await expect(getToken('', false, ''))
@ -127,3 +103,34 @@ describe('short lived tokens', () => {
.toEqual({"keys": [{"hostname": "dev", "key": "token"}]}) .toEqual({"keys": [{"hostname": "dev", "key": "token"}]})
}) })
}) })
describe('short lived tokens with retry', () => {
afterEach(() => {
nock.cleanAll()
nock.restore()
})
it('get short lived token fails when cannot connect', async () => {
nock('http://localhost:3333')
.post('/api/auth/token')
.times(3)
.replyWithError({
message: 'connect ECONNREFUSED 127.0.0.1:3333',
code: 'ECONNREFUSED'
})
await expect(getToken('localhost=key0', false, ''))
.resolves
.toBeNull()
})
it('get short lived token is null when request fails', async () => {
nock('http://dev:3333')
.post('/api/auth/token')
.times(3)
.reply(500, 'Internal error')
expect.assertions(1)
await expect(getToken('dev=xyz', false, ''))
.resolves
.toBeNull()
})
})

View File

@ -58,6 +58,7 @@ test('fetches wrapper jar checksums for snapshots', async () => {
describe('retry', () => { describe('retry', () => {
afterEach(() => { afterEach(() => {
nock.cleanAll() nock.cleanAll()
nock.restore()
}) })
describe('for /versions/all API', () => { describe('for /versions/all API', () => {