-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2244 from flacial/2243-add-the-ability-to-unlink-…
…a-discord-account Create unlinkDiscord resolver
- Loading branch information
Showing
6 changed files
with
154 additions
and
1 deletion.
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
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,9 @@ | ||
import { gql } from '@apollo/client' | ||
|
||
export const UNLINK_DISCORD = gql` | ||
mutation unlinkDiscord { | ||
unlinkDiscord { | ||
id | ||
} | ||
} | ||
` |
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,26 @@ | ||
import prismaMock from '../../__tests__/utils/prismaMock' | ||
import { unlinkDiscord } from './unlinkDiscord' | ||
|
||
const mockUser = { | ||
username: 'noob', | ||
id: 1 | ||
} | ||
|
||
const ctx = { req: { user: { id: 1 } } } | ||
const ctxWithError = { req: { user: { id: null } } } | ||
|
||
describe('unlinkDiscord resolver', () => { | ||
it('should unlink discord successfully', async () => { | ||
prismaMock.user.update.mockResolvedValue(mockUser) | ||
|
||
expect(unlinkDiscord(null, null, ctx)).resolves.toStrictEqual(mockUser) | ||
}) | ||
|
||
it('should throw error', async () => { | ||
prismaMock.user.update.mockResolvedValue(mockUser) | ||
|
||
expect(unlinkDiscord(null, null, ctxWithError)).rejects.toThrow( | ||
'Invalid user' | ||
) | ||
}) | ||
}) |
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,20 @@ | ||
import prisma from '../../prisma' | ||
import { Context } from '../../@types/helpers' | ||
|
||
export const unlinkDiscord = async (_parent: void, _: any, ctx: Context) => { | ||
const userId = ctx.req.user?.id | ||
|
||
if (!userId) throw new Error('Invalid user') | ||
|
||
return await prisma.user.update({ | ||
where: { | ||
id: userId | ||
}, | ||
data: { | ||
discordAccessToken: '', | ||
discordAccessTokenExpires: null, | ||
discordId: '', | ||
discordRefreshToken: '' | ||
} | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -122,6 +122,7 @@ export default gql` | |
title: String! | ||
id: Int! | ||
): [Lesson] | ||
unlinkDiscord: User | ||
} | ||
type AuthResponse { | ||
|
7335130
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
c0d3-app – ./
c0d3-app-git-master-c0d3-prod.vercel.app
c0d3-app.vercel.app
v2.c0d3.app
www.c0d3.com
c0d3-app-c0d3-prod.vercel.app