|
| 1 | +import { NoOpAuthenticator } from '../../src/authenticator' |
| 2 | +import { EndpointClient } from '../../src/endpoint-client' |
| 3 | +import { InvitesSchemaAppEndpoint, SchemaAppInvitation } from '../../src/endpoint/invites-schemaApp' |
| 4 | + |
| 5 | + |
| 6 | +afterEach(() => { |
| 7 | + jest.clearAllMocks() |
| 8 | +}) |
| 9 | + |
| 10 | +const postSpy = jest.spyOn(EndpointClient.prototype, 'post').mockImplementation() |
| 11 | +const getPagedItemsSpy = jest.spyOn(EndpointClient.prototype, 'getPagedItems').mockImplementation() |
| 12 | +const deleteSpy = jest.spyOn(EndpointClient.prototype, 'delete') |
| 13 | +const getSpy = jest.spyOn(EndpointClient.prototype, 'get').mockImplementation() |
| 14 | +const putSpy = jest.spyOn(EndpointClient.prototype, 'put').mockImplementation() |
| 15 | + |
| 16 | +const authenticator = new NoOpAuthenticator() |
| 17 | +const invitesEndpoint = new InvitesSchemaAppEndpoint( {authenticator}) |
| 18 | + |
| 19 | +test('create', async () => { |
| 20 | + const invitationId = { invitationId: 'my-invitation-id' } |
| 21 | + const createData = { schemaAppId: 'schema-app-id' } |
| 22 | + |
| 23 | + postSpy.mockResolvedValueOnce(invitationId) |
| 24 | + |
| 25 | + expect(await invitesEndpoint.create(createData)).toBe(invitationId) |
| 26 | + |
| 27 | + expect(postSpy).toHaveBeenCalledTimes(1) |
| 28 | + expect(postSpy).toHaveBeenCalledWith('', createData) |
| 29 | +}) |
| 30 | + |
| 31 | +test('list', async () => { |
| 32 | + const invitations = [{ id: 'my-invitation-id' } as SchemaAppInvitation] |
| 33 | + |
| 34 | + getPagedItemsSpy.mockResolvedValueOnce(invitations) |
| 35 | + |
| 36 | + expect(await invitesEndpoint.list('schema-app-id')).toBe(invitations) |
| 37 | + |
| 38 | + expect(getPagedItemsSpy).toHaveBeenCalledTimes(1) |
| 39 | + expect(getPagedItemsSpy).toHaveBeenCalledWith('', { schemaAppId: 'schema-app-id' }) |
| 40 | +}) |
| 41 | + |
| 42 | +test('revoke', async () => { |
| 43 | + await expect(invitesEndpoint.revoke('schema-app-id')).resolves.not.toThrow() |
| 44 | + |
| 45 | + expect(deleteSpy).toHaveBeenCalledTimes(1) |
| 46 | + expect(deleteSpy).toHaveBeenCalledWith('schema-app-id') |
| 47 | +}) |
| 48 | + |
| 49 | +test('getAcceptanceStatus', async () => { |
| 50 | + const status = [{ description: 'invitation description', isAccepted: true }] |
| 51 | + |
| 52 | + getSpy.mockResolvedValueOnce(status) |
| 53 | + |
| 54 | + expect(await invitesEndpoint.getAcceptanceStatus('invitation-id')).toBe(status) |
| 55 | + |
| 56 | + expect(getSpy).toHaveBeenCalledTimes(1) |
| 57 | + expect(getSpy).toHaveBeenCalledWith('checkAcceptance', { invitationId: 'invitation-id' }) |
| 58 | +}) |
| 59 | + |
| 60 | +test('accept', async () => { |
| 61 | + const schemaAppId = { schemaAppId: 'schema-app-id' } |
| 62 | + |
| 63 | + putSpy.mockResolvedValueOnce(schemaAppId) |
| 64 | + |
| 65 | + expect(await invitesEndpoint.accept('short-code')).toBe(schemaAppId) |
| 66 | + |
| 67 | + expect(putSpy).toHaveBeenCalledTimes(1) |
| 68 | + expect(putSpy).toHaveBeenCalledWith('short-code/accept') |
| 69 | +}) |
0 commit comments