Unverified Commit 49ec880f authored by Daz DeBoer's avatar Daz DeBoer
Browse files

Avoid open interceptors in unit test

parent f29f5a9d
Loading
Loading
Loading
Loading
+31 −24
Changes for sources/test/jest/short-lived-token.test.ts: 31 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -31,30 +31,6 @@ describe('short lived tokens', () => {
        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 () => {
        expect.assertions(1)
        await expect(getToken('', false, ''))
@@ -127,3 +103,34 @@ describe('short lived tokens', () => {
            .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()
    })
})
+1
Changes for sources/test/jest/wrapper-validation/checksums.test.ts: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ test('fetches wrapper jar checksums for snapshots', async () => {
describe('retry', () => {
  afterEach(() => {
    nock.cleanAll()
    nock.restore()
  })

  describe('for /versions/all API', () => {