-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
66 changes: 31 additions & 35 deletions
66
packages/client/lib/__tests__/IssuerSessionClient.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 |
---|---|---|
@@ -1,64 +1,60 @@ | ||
import { IssuerSessionIdRequestOpts } from '@sphereon/oid4vci-common'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import nock from 'nock' | ||
import { acquireIssuerSessionId } from '../IssuerSessionClient'; | ||
import nock from 'nock'; | ||
|
||
import { acquireIssuerSessionId } from '../IssuerSessionClient'; | ||
|
||
describe('IssuerSessionClient', () => { | ||
describe('acquireIssuerSessionId', () => { | ||
const mockSessionEndpoint = 'https://server.example.com/session_endpoint' | ||
const mockSessionId = 'iOiJSUzI1NiIsInR' | ||
const mockSessionEndpoint = 'https://server.example.com/session_endpoint'; | ||
const mockSessionId = 'iOiJSUzI1NiIsInR'; | ||
|
||
beforeEach(() => { | ||
nock.cleanAll() | ||
}) | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('should successfully acquire an issuer session ID', async () => { | ||
const mockResponse = { | ||
session_id: mockSessionId | ||
} | ||
session_id: mockSessionId, | ||
}; | ||
|
||
nock('https://server.example.com') | ||
.post('/session_endpoint') | ||
.reply(200, mockResponse, { 'Content-Type': 'application/json' }) | ||
nock('https://server.example.com').post('/session_endpoint').reply(200, mockResponse, { 'Content-Type': 'application/json' }); | ||
|
||
const opts: IssuerSessionIdRequestOpts = { | ||
sessionEndpoint: mockSessionEndpoint | ||
} | ||
sessionEndpoint: mockSessionEndpoint, | ||
}; | ||
|
||
const result = await acquireIssuerSessionId(opts) | ||
const result = await acquireIssuerSessionId(opts); | ||
|
||
expect(result).toEqual(mockResponse) | ||
}) | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should reject with an error if the response contains an error body', async () => { | ||
const mockErrorResponse = { | ||
error: 'invalid_request', | ||
error_description: 'The request is missing a required parameter' | ||
} | ||
error_description: 'The request is missing a required parameter', | ||
}; | ||
|
||
nock('https://server.example.com') | ||
.post('/session_endpoint') | ||
.reply(400, mockErrorResponse, { 'Content-Type': 'application/json' }) | ||
nock('https://server.example.com').post('/session_endpoint').reply(400, mockErrorResponse, { 'Content-Type': 'application/json' }); | ||
|
||
const opts: IssuerSessionIdRequestOpts = { | ||
sessionEndpoint: mockSessionEndpoint | ||
} | ||
sessionEndpoint: mockSessionEndpoint, | ||
}; | ||
|
||
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token/) | ||
}) | ||
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token/); | ||
}); | ||
|
||
it('should reject with an error if the response is missing the session_token', async () => { | ||
nock('https://server.example.com') | ||
.post('/session_endpoint') | ||
.reply(200, undefined, { 'Content-Type': 'application/json' }) | ||
nock('https://server.example.com').post('/session_endpoint').reply(200, undefined, { 'Content-Type': 'application/json' }); | ||
|
||
const opts: IssuerSessionIdRequestOpts = { | ||
sessionEndpoint: mockSessionEndpoint | ||
} | ||
|
||
await expect(acquireIssuerSessionId(opts)).rejects.toMatch(/an error occurred while requesting a issuer session token.*missing session_token response/) | ||
}) | ||
}) | ||
}) | ||
sessionEndpoint: mockSessionEndpoint, | ||
}; | ||
|
||
await expect(acquireIssuerSessionId(opts)).rejects.toMatch( | ||
/an error occurred while requesting a issuer session token.*missing session_token response/, | ||
); | ||
}); | ||
}); | ||
}); |
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
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