Skip to content

Commit

Permalink
feat: use user repo in stories
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Nov 29, 2024
1 parent 63a7cf9 commit 148cc26
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 23 deletions.
16 changes: 0 additions & 16 deletions src/sections/sign-up/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,11 @@ import { ValidTokenNotLinkedAccountForm } from './valid-token-not-linked-account
import styles from './SignUp.module.scss'

// TODO:ME - All use cases will return same error message so this is blocking us for making requests to other public use cases like get root collection, should work removing access token from localstorage but we need it for future call
// TODO:ME - How to handle 401 Unauthorized {"status":"ERROR","message":"Unauthorized bearer token."} globally, maybe redirect to oidc login page?
// TODO:ME - Maybe we should redirect to a welcome page after success? ask if there is one, maybe not the case for this scenario
// TODO:ME - Ask about the format of the terms of use, html string? just text string? what is shown in the box if there is just a url string ?
// TODO:ME - Ask about logout when clicking the Cancel button because of the BEARER_TOKEN_IS_VALID_BUT_NOT_LINKED_MESSAGE error
// TODO:ME - JS-DATAVERSE use case for registration
// TODO:ME - JS-DATAVERSE use case for getting the terms of use? how to avoid sending token in this case?

/*
This is the expected response from the server after succesfull registration, will help for js-dataverse-client-javascript
const resp = {
data: {
status: 'OK',
data: {
message: 'User registered.'
}
},
status: 200,
statusText: 'OK'
}
*/

interface SignUpProps {
userRepository: UserRepository
dataverseInfoRepository: DataverseInfoRepository
Expand Down
2 changes: 1 addition & 1 deletion src/stories/account/Account.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WithI18next } from '../WithI18next'
import { WithLayout } from '../WithLayout'
import { WithLoggedInUser } from '../WithLoggedInUser'
import { AccountHelper } from '../../sections/account/AccountHelper'
import { UserMockRepository } from './UserMockRepository'
import { UserMockRepository } from '../shared-mock-repositories/user/UserMockRepository'

const meta: Meta<typeof Account> = {
title: 'Pages/Account',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WithI18next } from '@/stories/WithI18next'
import { WithLayout } from '@/stories/WithLayout'
import { WithLoggedInUser } from '@/stories/WithLoggedInUser'
import { AccountHelper } from '@/sections/account/AccountHelper'
import { UserMockRepository } from '../UserMockRepository'
import { UserMockRepository } from '../../shared-mock-repositories/user/UserMockRepository'

const meta: Meta<typeof Account> = {
title: 'Sections/Account Page/AccountInfoSection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { WithI18next } from '@/stories/WithI18next'
import { WithLayout } from '@/stories/WithLayout'
import { WithLoggedInUser } from '@/stories/WithLoggedInUser'
import { AccountHelper } from '@/sections/account/AccountHelper'
import { UserMockRepository } from '../UserMockRepository'
import { UserMockLoadingRepository } from '../UserMockLoadingRepository'
import { UserMockErrorRepository } from '../UserMockErrorRepository'
import { UserMockRepository } from '../../shared-mock-repositories/user/UserMockRepository'
import { UserMockLoadingRepository } from '../../shared-mock-repositories/user/UserMockLoadingRepository'
import { UserMockErrorRepository } from '../../shared-mock-repositories/user/UserMockErrorRepository'

const meta: Meta<typeof Account> = {
title: 'Sections/Account Page/ApiTokenSection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ export class UserMockErrorRepository extends UserMockRepository {
}, FakerHelper.loadingTimout())
})
}

register(): Promise<void> {
return new Promise((_resolve, reject) => {
setTimeout(() => {
reject('Something went wrong registering the user. Try again later.')
}, FakerHelper.loadingTimout())
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export class UserMockLoadingRepository extends UserMockRepository {
deleteApiToken(): Promise<void> {
return new Promise(() => {})
}

register(): Promise<void> {
return new Promise(() => {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TokenInfo } from '@/users/domain/models/TokenInfo'
import { User } from '@/users/domain/models/User'
import { UserMother } from '@tests/component/users/domain/models/UserMother'
import { FakerHelper } from '@tests/component/shared/FakerHelper'
import { UserDTO } from '@/users/domain/useCases/DTOs/UserDTO'

export class UserMockRepository extends UserJSDataverseRepository {
getAuthenticated(): Promise<User> {
Expand Down Expand Up @@ -46,4 +47,12 @@ export class UserMockRepository extends UserJSDataverseRepository {
}, FakerHelper.loadingTimout())
})
}

register(_user: UserDTO): Promise<void> {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, FakerHelper.loadingTimout())
})
}
}
5 changes: 3 additions & 2 deletions src/stories/sign-up/SignUp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { SignUp } from '@/sections/sign-up/SignUp'
import { DataverseInfoMockRepository } from '../shared-mock-repositories/info/DataverseInfoMockRepository'
import { DataverseInfoMockLoadingRepository } from '../shared-mock-repositories/info/DataverseInfoMockLoadingkRepository'
import { WithOIDCAuthContext } from '../WithOIDCAuthContext'

// TODO:ME - After implementing register use case in js-dataverse, we should mock the register function here also.
import { UserMockRepository } from '../shared-mock-repositories/user/UserMockRepository'

const meta: Meta<typeof SignUp> = {
title: 'Pages/Sign Up',
Expand All @@ -23,6 +22,7 @@ type Story = StoryObj<typeof SignUp>
export const ValidTokenWithNotLinkedAccount: Story = {
render: () => (
<SignUp
userRepository={new UserMockRepository()}
dataverseInfoRepository={new DataverseInfoMockRepository()}
hasValidTokenButNotLinkedAccount
/>
Expand All @@ -32,6 +32,7 @@ export const ValidTokenWithNotLinkedAccount: Story = {
export const Loading: Story = {
render: () => (
<SignUp
userRepository={new UserMockRepository()}
dataverseInfoRepository={new DataverseInfoMockLoadingRepository()}
hasValidTokenButNotLinkedAccount
/>
Expand Down

0 comments on commit 148cc26

Please sign in to comment.