-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from algorandfoundation/chore/unit-tests-for-co…
…nnect-module chore/unit-tests-for-connect-module
- Loading branch information
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
services/liquid-auth-api-js/src/connect/connect.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AlgodService } from '../algod/algod.service'; | ||
import { ConnectController } from './connect.controller'; | ||
import { AuthService } from '../auth/auth.service'; | ||
import { Session } from './session.schema'; | ||
import { accFixture } from '../../tests/constants'; | ||
import { mockAuthService } from '../__mocks__/auth.service.mock'; | ||
import { mockAccountLinkService } from '../__mocks__/account-link.service.mock'; | ||
|
||
describe('ConnectController', () => { | ||
let connectController: ConnectController; | ||
|
||
beforeEach(async () => { | ||
const moduleRef: TestingModule = await Test.createTestingModule({ | ||
controllers: [ConnectController], | ||
providers: [ | ||
{ | ||
provide: AuthService, | ||
useValue: { ...mockAuthService }, | ||
}, | ||
{ | ||
provide: 'ACCOUNT_LINK_SERVICE', | ||
useValue: { ...mockAccountLinkService }, | ||
}, | ||
{ | ||
provide: AlgodService, | ||
useValue: { | ||
accountInformation: jest.fn().mockReturnThis(), | ||
exclude: jest.fn().mockReturnThis(), | ||
do: jest.fn().mockResolvedValue({ | ||
'auth-addr': accFixture.accs[1].addr, | ||
}), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
connectController = moduleRef.get<ConnectController>(ConnectController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(connectController).toBeDefined(); | ||
}); | ||
|
||
describe('connect response', () => { | ||
it('(CREATED) should return undefined when a valid account & signature requests to connect', async () => { | ||
const session = new Session(); | ||
|
||
const linkResponseDTO = { | ||
requestId: 0, | ||
wallet: accFixture.accs[0].addr, | ||
challenge: accFixture.challenge, | ||
signature: accFixture.accs[0].signature, | ||
credId: '', | ||
}; | ||
|
||
const response = await connectController.linkWalletResponse( | ||
session, | ||
linkResponseDTO, | ||
); | ||
|
||
expect(response).toBe(undefined); | ||
}); | ||
|
||
it("(FAIL) should throw an error when the signature doesn't match the account", async () => { | ||
const session = new Session(); | ||
|
||
const linkResponseDTO = { | ||
requestId: 0, | ||
wallet: accFixture.accs[0].addr, | ||
challenge: accFixture.challenge, | ||
signature: accFixture.accs[2].signature, | ||
credId: '', | ||
}; | ||
|
||
await expect( | ||
connectController.linkWalletResponse(session, linkResponseDTO), | ||
).rejects.toThrowError(); | ||
}); | ||
|
||
it('(CREATED) should return undefined when a valid account & auth address signature requests to connect', async () => { | ||
const session = new Session(); | ||
|
||
const linkResponseDTO = { | ||
requestId: 0, | ||
wallet: accFixture.accs[0].addr, | ||
challenge: accFixture.challenge, | ||
signature: accFixture.accs[1].signature, | ||
credId: '', | ||
}; | ||
|
||
const response = await connectController.linkWalletResponse( | ||
session, | ||
linkResponseDTO, | ||
); | ||
|
||
expect(response).toBe(undefined); | ||
}); | ||
}); | ||
}); |