Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEMO CODE] Subscription purchase process #11

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"baseUrl": "http://localhost:3001"
"baseUrl": "http://localhost:3001",
"chromeWebSecurity": false

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
describe('Registered and logged in user can purchase a subscription', () => {
beforeEach(() => {
cy.server();
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles",
response: "fixture:articles_index.json"
});
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles/2",
response: "fixture:specific_article_2.json"
});

cy.route({
method: 'POST',
url: "http://localhost:3000/api/subscriptions",
response: { status: 'paid' }
}).as('purchase')

cy.visit("/");
cy.window()
.then(window => {
window.store.dispatch(
{
type: "AUTHENTICATE",
payload: { currentUser: { email: '[email protected]', role: '' } }
}
)
})
cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
});

it('by clicking Buy Subscription', () => {
cy.get('button').contains('Buy Subscription').click()
cy.get('form[id="subscription-form"]')
.should('be.visible')
cy.get('form[id="subscription-form"]').within(() => {

cy.typeInStripeElement('cardnumber', '4242424242424242')
cy.typeInStripeElement('exp-date', '1220')
cy.typeInStripeElement('cvc', '123')

cy.get('button').contains('Submit payment').click()
})
cy.wait('@purchase')
cy.get('h2[id="message"]').should('contain', "Thank you for your business!")

cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')

});
});
267 changes: 133 additions & 134 deletions cypress/integration/userCanOnlySeeValidContent.feature.js
Original file line number Diff line number Diff line change
@@ -1,148 +1,147 @@
describe("Aricle view:", () => {
beforeEach(() => {
cy.server();
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles",
response: "fixture:articles_index.json"
});
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles/2",
response: "fixture:specific_article_2.json"
});
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles/1",
response: "fixture:specific_article_1.json"
});
cy.visit("/");
});
beforeEach(() => {
cy.server();
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles",
response: "fixture:articles_index.json"
});
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles/2",
response: "fixture:specific_article_2.json"
});
cy.route({
method: "GET",
url: "http://localhost:3000/api/articles/1",
response: "fixture:specific_article_1.json"
});
cy.visit("/");
});

it("Not logged will be able to read free articles but not premium articles", () => {
cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')
it("Not logged will be able to read free articles but not premium articles", () => {
cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')

cy.get('button')
.contains("Back")
.click()
cy.get('button')
.contains("Back")
.click()

cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
cy.get(".spec-content").should("contain", "...");
cy.get('p').should("contain", 'This article require a premium membership.')
})
});
cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
cy.get(".spec-content").should("contain", "...");
cy.get('p').should("contain", 'This article require a premium membership.')
})
});

it('Authenticated user that is NOT a SUBSCRIBER can only read free articles but not premium articles', () => {
cy.window()
.then(window => {
window.store.dispatch(
{
type: "AUTHENTICATE",
payload: { currentUser: { email: '[email protected]', role: '' } }
}
)
})
it('Authenticated user that is NOT a SUBSCRIBER can only read free articles but not premium articles', () => {
cy.window()
.then(window => {
window.store.dispatch(
{
type: "AUTHENTICATE",
payload: { currentUser: { email: '[email protected]', role: '' } }
}
)
})

cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')
cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')

cy.get('button')
.contains("Back")
.click()
cy.get('button')
.contains("Back")
.click()

cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
cy.get(".spec-content").should("contain", "...");
cy.get('p').should("contain", 'This article require a premium membership.')
})
});
cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
cy.get(".spec-content").should("contain", "...");
cy.get('p').should("contain", 'This article require a premium membership.')
})
});

it('Authenticated user that is a SUBSCRIBER can se full length of all articles', () => {
cy.window()
.then(window => {
window.store.dispatch(
{
type: "AUTHENTICATE",
payload: { currentUser: { email: '[email protected]', role: 'subscriber' } }
})
})
it('Authenticated user that is a SUBSCRIBER can se full length of all articles', () => {
cy.window()
.then(window => {
window.store.dispatch(
{
type: "AUTHENTICATE",
payload: { currentUser: { email: '[email protected]', role: 'subscriber' } }
})
})

cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')
cy.get("#1")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Free Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')

cy.get('button')
.contains("Back")
.click()

cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')
});
cy.get('button')
.contains("Back")
.click()
cy.get("#2")
.last()
.within(() => {
cy.get("button")
.contains("Read More")
.click();
});
cy.get(".article")
.within(() => {
cy.get(".spec-title").should("contain", "Premium Article");
})
cy.get(".article")
.should("not.contain", "...")
.and("not.contain", 'This article require a premium membership.')
});


});
10 changes: 10 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

Cypress.Commands.add('typeInStripeElement', (element, value) => {
cy.get(`#${element} div iframe`)
.then($iframe => {
const $body = $iframe.contents().find("body");
cy.wrap($body)
.find(`input[name^="${element}"]`)
.type(value, { delay: 10 });
});
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react-dom": "^16.13.0",
"react-redux": "^7.2.0",
"react-scripts": "3.4.0",
"react-stripe-elements": "^6.1.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"styled-components": "^5.0.1"
Expand Down
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
-->
<script src="https://js.stripe.com/v3/"></script>
<title>React App</title>
</head>
<body>
Expand Down
Loading