Skip to content

Commit

Permalink
Fix tests with token from user
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsimper committed Nov 4, 2019
1 parent a1f4ab5 commit f2edb0a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion runs/graphql/src/resolvers/me.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getUser } from "../services/firebase.js";

export const me = async (parent, args, context) => {
const doc = await getUser(context.user.user_id);
console.log({ context });
const doc = await getUser(context.token.user_id);
if (!doc.exists) {
throw Error("No such user!");
}
Expand Down
2 changes: 1 addition & 1 deletion runs/graphql/src/resolvers/me.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("me to return", async () => {
data: () => fakeUser
})
);
const user = await me({}, {}, { user: { user_id: "fake" } });
const user = await me({}, {}, { token: { user_id: "fake" } });
expect(user).toEqual(fakeUser);
expect(getUser).lastCalledWith("fake");
});
4 changes: 2 additions & 2 deletions runs/graphql/src/resolvers/updateprofile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { updateUser } from "../services/firebase.js";

export const updateProfile = async (parent, arg, context) => {
if (!context.user) {
if (!context.token) {
throw new Error("Can't update with no user");
}
const data = await updateUser(context.user.user_id, arg.input);
const data = await updateUser(context.token.user_id, arg.input);
return arg.input;
};
2 changes: 1 addition & 1 deletion runs/graphql/src/resolvers/updateprofile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("updateProfile with user", async () => {
const profile = await updateProfile(
null,
{ input: userInput },
{ user: { user_id: "donald" } }
{ token: { user_id: "donald" } }
);
expect(profile).toEqual(userInput);
expect(updateUser).lastCalledWith("donald", {
Expand Down
2 changes: 1 addition & 1 deletion runs/graphql/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const context = async ({ req }) => {
const decodedToken = await decodeJWT(token);
if (decodedToken) {
const user = await getUser(decodedToken.user_id);
return { token: decodedToken, user: user.docs[0] };
return { token: decodedToken, user: user.data() };
}
return {
token: undefined,
Expand Down

0 comments on commit f2edb0a

Please sign in to comment.