-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(frontend) add auth token into generated api
Generated api client need's to handle joanie authentification
- Loading branch information
1 parent
bfadf58
commit bb4c252
Showing
2 changed files
with
45 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import fetchMock from 'fetch-mock'; | ||
import { RichieContextFactory as mockRichieContextFactory } from 'utils/test/factories/richie'; | ||
import { RICHIE_USER_TOKEN } from 'settings'; | ||
|
||
import { joanieApi } from '..'; | ||
|
||
jest.mock('utils/context', () => ({ | ||
__esModule: true, | ||
default: mockRichieContextFactory({ | ||
authentication: { backend: 'fonzie', endpoint: 'https://demo.endpoint' }, | ||
joanie_backend: { endpoint: 'https://joanie.endpoint' }, | ||
}).one(), | ||
})); | ||
|
||
describe('joanieApi', () => { | ||
it('test', async () => { | ||
fetchMock.get('https://joanie.endpoint/api/v1.0/addresses/addressId/', []); | ||
await joanieApi.api.apiV10AddressesRetrieve('addressId'); | ||
|
||
let lastCall = fetchMock.lastCall(); | ||
const visitorHeader = lastCall && lastCall[1]?.headers; | ||
// TS see visitorHeader has HeadersInit instead of Headers and | ||
// didn't accept get() as a possible function. | ||
// @ts-ignore | ||
expect(visitorHeader?.get('Authorization')).toBeNull(); | ||
|
||
sessionStorage.setItem(RICHIE_USER_TOKEN, 'TEST_TOKEN'); | ||
await joanieApi.api.apiV10AddressesRetrieve('addressId'); | ||
lastCall = fetchMock.lastCall(); | ||
const userHeader = lastCall && lastCall[1]?.headers; | ||
// @ts-ignore | ||
expect(userHeader?.get('Authorization')).toBe('Bearer TEST_TOKEN'); | ||
}); | ||
}); |
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