This repository has been archived by the owner on Mar 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
[WIP] add addSocialMediaAccount mutation #233
Open
Kachulio1
wants to merge
3
commits into
master
Choose a base branch
from
125-list-social-media-accounts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−39
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import encode from '../jwt/encode' | ||
import bcrypt from 'bcryptjs' | ||
import { AuthenticationError } from 'apollo-server' | ||
import { neo4jgraphql } from 'neo4j-graphql-js' | ||
import encode from "../jwt/encode" | ||
import bcrypt from "bcryptjs" | ||
import { AuthenticationError } from "apollo-server" | ||
import { neo4jgraphql } from "neo4j-graphql-js" | ||
|
||
export default { | ||
Query: { | ||
|
@@ -25,7 +25,7 @@ export default { | |
|
||
return true | ||
}, | ||
login: async (parent, { email, password }, { driver, req, user }) => { | ||
login: async (_, { email, password }, { driver, req, user }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What renaming the parent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not using it, so I thought I could use a convention that I have seen, where the _ indicates that I'm not going to use that parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it also helps with the linter |
||
// if (user && user.id) { | ||
// throw new Error('Already logged in.') | ||
// } | ||
|
@@ -100,6 +100,25 @@ export default { | |
|
||
return encode(currentUser) | ||
} | ||
}, | ||
addSocialMedia: async (_, { url }, { driver, user }) => { | ||
const session = driver.session() | ||
|
||
const { email } = user | ||
const result = await session.run( | ||
`MATCH (user:User {email: $userEmail}) | ||
SET user.socialMedia = [$url] | ||
RETURN user {.socialMedia}`, | ||
{ | ||
userEmail: email, | ||
url | ||
} | ||
) | ||
session.close() | ||
const [currentUser] = result.records.map(record => { | ||
return record.get("user") | ||
}) | ||
return !!currentUser.socialMedia | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import Factory from '../seed/factories' | ||
import { GraphQLClient, request } from 'graphql-request' | ||
import jwt from 'jsonwebtoken' | ||
import { host, login } from '../jest/helpers' | ||
import Factory from "../seed/factories"; | ||
import { GraphQLClient, request } from "graphql-request"; | ||
import jwt from "jsonwebtoken"; | ||
import { host, login } from "../jest/helpers"; | ||
|
||
const factory = Factory() | ||
const factory = Factory(); | ||
|
||
// here is the decoded JWT token: | ||
// { | ||
|
@@ -117,37 +117,37 @@ describe('currentUser', () => { | |
role | ||
} | ||
}` | ||
}`; | ||
|
||
describe('unauthenticated', () => { | ||
it('returns null', async () => { | ||
const expected = { currentUser: null } | ||
await expect(request(host, query)).resolves.toEqual(expected) | ||
}) | ||
}) | ||
describe("unauthenticated", () => { | ||
it("returns null", async () => { | ||
const expected = { currentUser: null }; | ||
await expect(request(host, query)).resolves.toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('with valid JWT Bearer Token', () => { | ||
let client | ||
let headers | ||
describe("with valid JWT Bearer Token", () => { | ||
let client; | ||
let headers; | ||
|
||
describe('but no corresponding user in the database', () => { | ||
describe("but no corresponding user in the database", () => { | ||
beforeEach(async () => { | ||
client = new GraphQLClient(host, { headers: jennyRostocksHeaders }) | ||
}) | ||
client = new GraphQLClient(host, { headers: jennyRostocksHeaders }); | ||
}); | ||
|
||
it('returns null', async () => { | ||
const expected = { currentUser: null } | ||
await expect(client.request(query)).resolves.toEqual(expected) | ||
}) | ||
}) | ||
it("returns null", async () => { | ||
const expected = { currentUser: null }; | ||
await expect(client.request(query)).resolves.toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('and corresponding user in the database', () => { | ||
describe("and corresponding user in the database", () => { | ||
beforeEach(async () => { | ||
headers = await login({ email: '[email protected]', password: '1234' }) | ||
client = new GraphQLClient(host, { headers }) | ||
}) | ||
headers = await login({ email: "[email protected]", password: "1234" }); | ||
client = new GraphQLClient(host, { headers }); | ||
}); | ||
|
||
it('returns the whole user object', async () => { | ||
it("returns the whole user object", async () => { | ||
const expected = { | ||
currentUser: { | ||
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg', | ||
|
@@ -185,11 +185,11 @@ describe('login', () => { | |
) | ||
const token = data.login | ||
jwt.verify(token, process.env.JWT_SECRET, (err, data) => { | ||
expect(data.email).toEqual('[email protected]') | ||
expect(err).toBeNull() | ||
}) | ||
}) | ||
}) | ||
expect(data.email).toEqual("[email protected]"); | ||
expect(err).toBeNull(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('valid email/password but user is disabled', () => { | ||
it('responds with "Your account has been disabled."', async () => { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
e could also mean event, as a good practice use err or error instead.
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.
Yeah, I will change that, and how was that merged to master with a syntax error merged.
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.
That’s a really good question.