This file contains hidden or 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
const verifyAccount = assign({ | |
accountVerified: (context, event) => true | |
}); | |
const machine = Machine({ | |
id: 'verification', | |
initial: 'softIDCheck', | |
context: { | |
retries: 0, | |
accountVerified: false, |
This file contains hidden or 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
const verifyAccount = assign({ | |
accountVerified: (context, event) => true | |
}); | |
const incrementRetries = assign({ | |
retries: (context, event) => context.retries + 1 | |
}); | |
const machine = Machine({ | |
id: 'verification', |
This file contains hidden or 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains hidden or 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
import React, { Component } from "react"; | |
import { Query } from "react-apollo"; | |
import gql from "graphql-tag"; | |
const CommentsQuery = gql` | |
query Comments($postId: ID!, $cursor: String) { | |
commentsForPost(postId: $postId, cursor: $cursor) { | |
# __typeName | |
edges { | |
node { |
This file contains hidden or 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
it("returns a user if user is logged in and downgrade was successful", async () => { | |
const credentials = { login: "jacob", password: "password" }; | |
const response = await userApi.login(credentials); | |
const cookie = response.headers["set-cookie"][0]; | |
const result = await userApi.downgradeToBasic(cookie); | |
const expectedResult = { | |
data: { | |
downgradeToBasic: { |
This file contains hidden or 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
it("throws an error if user is not logged in.", async () => { | |
const variables = { stripeToken: "tok_visa" }; | |
const cookie = null; | |
const result = await userApi.downgradeToBasic(cookie); | |
const expectedError = "Please log in first."; | |
expect(result.data.errors[0].message).to.eql(expectedError); | |
}); |
This file contains hidden or 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
export const downgradeToBasic = async (cookie) => { | |
return await axios.post( | |
API_URL, | |
{ | |
query: ` | |
mutation { | |
downgradeToBasic { | |
id | |
username | |
role |
This file contains hidden or 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
it("returns a user with role set to Premium if the Stripe token is valid and user is logged in.", async () => { | |
const credentials = { login: "jacob", password: "password" }; | |
const response = await userApi.login(credentials); | |
const cookie = response.headers["set-cookie"][0]; | |
const variables = { stripeToken: "tok_visa" }; | |
const result = await userApi.upgradeToPremium(variables, cookie); | |
const expectedResult = { | |
data: { |
This file contains hidden or 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
{ | |
downgradeToBasic: async (parent, args, { models, me, res }) => { | |
if (!me) throw new Error("Please log in first."); | |
if (me.role === "BASIC") { | |
throw new Error( | |
"You already have a Basic account. Upgrade to Premium to get the full experience." | |
); | |
} |
This file contains hidden or 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
{ | |
upgradeToPremium: async (parent, { stripeToken }, { models, me, res }) => { | |
if (!me) throw new Error("Please log in first."); | |
if (me.role === "PREMIUM") | |
throw new Error("You already have a Premium account. Enjoy!"); | |
try { | |
const stripeCustomer = await stripe.customers.create({ | |
description: `Customer for ${me.email}`, | |
email: me.email, |
NewerOlder