@@ -4,11 +4,20 @@ import {
44 DataverseApiAuthMechanism
55} from '../../../src/core/infra/repositories/ApiConfig'
66import { TestConstants } from '../../testHelpers/TestConstants'
7- import { ReadError } from '../../../src'
7+ import { ReadError , WriteError } from '../../../src'
8+ import { createApiTokenViaApi } from '../../testHelpers/users/apiTokenHelper'
89
910describe ( 'UsersRepository' , ( ) => {
1011 const sut : UsersRepository = new UsersRepository ( )
1112
13+ afterAll ( async ( ) => {
14+ ApiConfig . init (
15+ TestConstants . TEST_API_URL ,
16+ DataverseApiAuthMechanism . API_KEY ,
17+ process . env . TEST_API_KEY
18+ )
19+ } )
20+
1221 describe ( 'getCurrentAuthenticatedUser' , ( ) => {
1322 test ( 'should return error when authentication is not valid' , async ( ) => {
1423 ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . API_KEY , 'invalidApiKey' )
@@ -28,5 +37,19 @@ describe('UsersRepository', () => {
2837 } )
2938 } )
3039
31- describe ( 'recreateApiToken' , ( ) => { } )
40+ describe ( 'recreateApiToken' , ( ) => {
41+ test ( 'should recreate API token when valid authentication is provided' , async ( ) => {
42+ const testApiToken = await createApiTokenViaApi ( )
43+ ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . API_KEY , testApiToken )
44+ const actualRecreatedApiToken = await sut . recreateApiToken ( )
45+ expect ( actualRecreatedApiToken ) . not . toBe ( testApiToken )
46+ } )
47+
48+ test ( 'should return error when authentication is not valid' , async ( ) => {
49+ ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . API_KEY , 'invalidApiKey' )
50+
51+ const errorExpected : WriteError = new WriteError ( '[401] Bad API key' )
52+ await expect ( sut . recreateApiToken ( ) ) . rejects . toThrow ( errorExpected )
53+ } )
54+ } )
3255} )
0 commit comments