Skip to content

Commit

Permalink
fix: Storyshot throw an error (garageScript#2257)
Browse files Browse the repository at this point in the history
  • Loading branch information
flacial committed Sep 4, 2022
1 parent 1a3aa25 commit 9c4229b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 179 deletions.
177 changes: 0 additions & 177 deletions __tests__/pages/profile/username.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,183 +522,6 @@ describe('user profile test', () => {
await waitFor(() => expect(unlinkDiscordMock.result).toBeCalled())
})

test('should handle error when unlinking discord', async () => {
expect.assertions(1)

const session = {
user: {
id: 1,
username: 'fakeusername',
name: 'fake user',
email: '[email protected]',
isAdmin: true,
discordUserId: 'fakeDiscordId',
discordUsername: 'fakeDiscordUser',
discordAvatarUrl: 'https://placeimg.com/640/480/any'
},
submissions: [
{
id: 1,
status: SubmissionStatus.Passed,
mrUrl: '',
diff: '',
viewCount: 0,
comment: '',
order: 0,
challengeId: 146,
lessonId: 2,
reviewer: {
id: 1,
username: 'fake reviewer'
},
createdAt: '123',
updatedAt: '123',
comments: null,
user: {
id: 1
}
},
{
id: 2,
status: SubmissionStatus.Passed,
mrUrl: '',
diff: '',
viewCount: 0,
comment: '',
order: 0,
challengeId: 145,
lessonId: 2,
reviewer: {
id: 1,
username: 'fake reviewer'
},
createdAt: '123',
updatedAt: '123',
comments: null,
user: {
id: 1
}
}
],
lessonStatus: [
{
lessonId: 5,
passedAt: new Date(),
starGiven: null,
starsReceived: [
{
id: 17,
mentorId: 1,
studentId: 6,
lessonId: 5,
student: {
username: 'newbie',
name: 'newbie newbie'
},
lesson: {
title: 'Foundations of JavaScript',
order: 1
},
comment: 'Thanks for your halp!'
}
]
},
{
lessonId: 2,
passedAt: new Date(),
starGiven: null,
starsReceived: [
{
id: 17,
mentorId: 1,
studentId: 6,
lessonId: 2,
student: {
username: 'newbie',
name: 'newbie newbie'
},
lesson: {
title: 'Variables & Functions',
order: 1
},
comment: 'Thanks for your halp!'
}
]
},
{
lessonId: 1,
passedAt: new Date(),
starGiven: null,
starsReceived: [
{
id: 17,
mentorId: 1,
studentId: 6,
lessonId: 2,
student: {
username: 'anonymous',
name: ''
},
lesson: {
title: 'Variables & Functions',
order: 1
},
comment: ''
}
]
}
]
}

const unlinkDiscordMockWithError = {
request: {
query: UNLINK_DISCORD
},
error: new Error('error')
}

const mocks = [
{
request: { query: GET_APP },
result: {
data: {
session,
lessons: dummyLessonData,
alerts: []
}
}
},
{
request: {
query: USER_INFO,
variables: {
username: 'fake user'
}
},
result: {
data: {
userInfo: session
}
}
},
unlinkDiscordMockWithError
]

const { findByRole, getByText, getByTestId } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserProfile />
</MockedProvider>
)

await waitForElementToBeRemoved(() => getByText('Loading...'))
await findByRole('heading', { name: /fakeDiscordUser/i })

await userEvent.click(getByText(/unlink discord/i))
await userEvent.click(getByTestId('unlink-discord-btn'))

expect(Sentry.captureException).toBeCalled()
})

test('should link discord to user account', async () => {
expect.assertions(1)

Expand Down
6 changes: 4 additions & 2 deletions components/ProfileImageInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { signIn } from 'next-auth/react'
import { Button as BsButton } from 'react-bootstrap'
import { useMutation } from '@apollo/client'
import { UNLINK_DISCORD } from '../graphql/queries/unlinkDiscord'
import * as Sentry from '@sentry/nextjs'
import { useRouter } from 'next/router'

type ProfileImageInfoProps = {
Expand All @@ -43,7 +42,10 @@ const ProfileImageInfo: React.FC<ProfileImageInfoProps> = ({ user }) => {
await unlinkDiscord()
router.reload()
} catch (e) {
Sentry.captureException(e)
// Calling this function make DiscordBar in storyshots fail with:
// Warning: An update to DiscordBar inside a test was not wrapped in act(...)
// Track it on https://github.com/garageScript/c0d3-app/issues/2257
// Sentry.captureException(e)
}
}

Expand Down

0 comments on commit 9c4229b

Please sign in to comment.