-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read current api usecase with fake promise data
- Loading branch information
1 parent
ff8ed38
commit d85c671
Showing
10 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface TokenInfo { | ||
apiToken: string | ||
expirationDate: string | ||
} |
7 changes: 7 additions & 0 deletions
7
src/api-token-info/domain/repositories/ApiTokenInfoRepository.tsx
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,7 @@ | ||
import { TokenInfo } from '../models/TokenInfo' | ||
|
||
export interface ApiTokenInfoRepository { | ||
getCurrentApiToken(): Promise<TokenInfo> | ||
recreateApiToken(): Promise<TokenInfo> | ||
deleteApiToken(): Promise<void> | ||
} |
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,8 @@ | ||
import { TokenInfo } from '../models/TokenInfo' | ||
import { ApiTokenInfoRepository } from '../repositories/ApiTokenInfoRepository' | ||
|
||
export function readCurrentApiToken( | ||
apiTokenRepository: ApiTokenInfoRepository | ||
): Promise<TokenInfo> { | ||
return apiTokenRepository.getCurrentApiToken() | ||
} |
56 changes: 56 additions & 0 deletions
56
src/api-token-info/infrastructure/ApiTokenInfoJSDataverseRepository.tsx
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,56 @@ | ||
// import { ReadError } from '@iqss/dataverse-client-javascript' | ||
// import { | ||
// getCurrentApiToken, | ||
// recreateCurrentApiToken, | ||
// deleteCurrentApiToken, | ||
// ApiTokenInfo | ||
// } from '@iqss/dataverse-client-javascript' | ||
|
||
import { TokenInfo } from '../domain/models/TokenInfo' | ||
import { ApiTokenInfoRepository } from '../domain/repositories/ApiTokenInfoRepository' | ||
|
||
export class ApiTokenInfoJSDataverseRepository implements ApiTokenInfoRepository { | ||
getCurrentApiToken(): Promise<TokenInfo> { | ||
return Promise.resolve({ | ||
apiToken: '142354345435eefrr', | ||
expirationDate: new Date().toISOString().substring(0, 10) | ||
}) | ||
} | ||
recreateApiToken(): Promise<TokenInfo> { | ||
return Promise.resolve({ | ||
apiToken: 'apiToken', | ||
expirationDate: new Date().toISOString().substring(0, 10) | ||
}) | ||
} | ||
|
||
deleteApiToken(): Promise<void> { | ||
return Promise.resolve() | ||
} | ||
// getCurrentApiToken(): Promise<TokenInfo> { | ||
// return execute() | ||
// .then((apiTokenInfo: TokenInfo) => { | ||
// return { | ||
// apiToken: apiTokenInfo.apiToken, | ||
// expirationDate: apiTokenInfo.expirationDate | ||
// } | ||
// }) | ||
// .catch((error: ReadError) => { | ||
// throw new Error(error.message) | ||
// }) | ||
// } | ||
// recreateApiToken(): Promise<TokenInfo> { | ||
// return recreateCurrentApiToken | ||
// .execute() | ||
// .then((apiTokenInfo: ApiTokenInfo) => { | ||
// return { | ||
// apiToken: apiTokenInfo.apiToken, | ||
// expirationDate: apiTokenInfo.expirationDate | ||
// } | ||
// }) | ||
// .catch((error: ReadError) => { | ||
// throw new Error(error.message) | ||
// }) | ||
// } | ||
// deleteApiToken(): Promise<void> { | ||
// return deleteCurrentApiToken()} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/sections/account/api-token-section/ApiTokenSectionSkeleton.tsx
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,37 @@ | ||
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton' | ||
import 'react-loading-skeleton/dist/skeleton.css' | ||
import { Button } from '@iqss/dataverse-design-system' | ||
import styles from './ApiTokenSection.module.scss' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
const ApiTokenSectionSkeleton = () => { | ||
const { t } = useTranslation('account', { keyPrefix: 'apiToken' }) | ||
|
||
return ( | ||
<SkeletonTheme> | ||
<> | ||
<p className={styles['exp-date']}> | ||
{t('expirationDate')}{' '} | ||
<time data-testid="expiration-date"> | ||
<Skeleton width={100} /> | ||
</time> | ||
</p> | ||
<div className={styles['api-token']}> | ||
<code data-testid="api-token"> | ||
<Skeleton /> | ||
</code> | ||
</div> | ||
<div className={styles['btns-wrapper']} role="group"> | ||
<Button variant="secondary">{t('copyToClipboard')}</Button> | ||
<Button variant="secondary" disabled> | ||
{t('recreateToken')} | ||
</Button> | ||
<Button variant="secondary" disabled> | ||
{t('revokeToken')} | ||
</Button> | ||
</div> | ||
</> | ||
</SkeletonTheme> | ||
) | ||
} | ||
export default ApiTokenSectionSkeleton |
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
24 changes: 24 additions & 0 deletions
24
...integration/account/infrastructure/repositories/ApiTokenInfoJSDataverseRepository.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,24 @@ | ||
import { ApiTokenInfoJSDataverseRepository } from '../../../../../../src/api-token-info/infrastructure/ApiTokenInfoJSDataverseRepository' | ||
import { TokenInfo } from '../../../../../../src/api-token-info/domain/models/TokenInfo' | ||
//TODO: we need to change the fake call to the real one once we have the api working | ||
const apiTokenRepository = new ApiTokenInfoJSDataverseRepository() | ||
const tokenInfoExpected: TokenInfo = { | ||
apiToken: '142354345435eefrr', | ||
expirationDate: '2024-10-16' | ||
} | ||
|
||
describe('get api Token Repository', () => { | ||
it('should return the current api token', async () => { | ||
const tokenInfo = await apiTokenRepository.getCurrentApiToken() | ||
expect(tokenInfo).to.deep.equal(tokenInfoExpected) | ||
}) | ||
|
||
it('should return a new api token', async () => { | ||
const tokenInfo = await apiTokenRepository.recreateApiToken() | ||
expect(tokenInfo).to.deep.equal(tokenInfo) | ||
}) | ||
|
||
it('should delete the current api token', async () => { | ||
await apiTokenRepository.deleteApiToken() | ||
}) | ||
}) |