Skip to content

Commit

Permalink
feat: implemented user auth using Identity
Browse files Browse the repository at this point in the history
  • Loading branch information
vickywane committed Feb 27, 2021
1 parent 11c6dc7 commit bd85dfe
Show file tree
Hide file tree
Showing 22 changed files with 27,595 additions and 18,165 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
# local env files
.env.local
.env.*.local
.env

# Log files
npm-debug.log*
Expand All @@ -26,4 +27,4 @@ cypress/screenshots/

# Test coverage reports
.nyc_output/
coverage/
coverage/
56 changes: 28 additions & 28 deletions cypress/integration/ambianic-tests/navbar.spec.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
/// <reference types="cypress" />

context('Check Navbar Items', () => {
before(() => {
cy.visit('http://localhost:8080')
cy.get('[data-cy=timeline]').click()
})
before(() => {
cy.visit('http://localhost:8080')
cy.get('[data-cy=timeline]').click()
})

it('Should have a search bar', () => {
cy.get('[data-cy=container').find("#searchbar")
})
it('Should have a search bar', () => {
cy.get('[data-cy=container').find('#searchbar')
})

it('Should be a download off button', () => {
const t = cy.get('[data-cy=download-off]')
expect(t).to.exist
})
it('Should be a download off button', () => {
const t = cy.get('[data-cy=download-off]')
expect(t).to.exist
})

it('Should be a heart button', () => {
const t = cy.get('[data-cy=heart]')
expect(t).to.exist
})
it('Should be a heart button', () => {
const t = cy.get('[data-cy=heart]')
expect(t).to.exist
})

it('Should be a bell button', () => {
const t = cy.get('[data-cy=bell]')
expect(t).to.exist
})
it('Should be a bell button', () => {
const t = cy.get('[data-cy=bell]')
expect(t).to.exist
})

it('Should be an about button', () => {
const t = cy.get('[data-cy=about]')
expect(t).to.exist
})
it('Should have user profile component card', () => {
const t = cy.get('[data-cy=profile-component]')
expect(t).to.exist
})

it('Should have a five links', () => {
cy.get('[data-cy=drawer]').then(($result) => {
assert.equal($result.children().children()[0].childElementCount,5,'Five links in the drawer')
})
it('Should have a five links', () => {
cy.get('[data-cy=drawer]').then(($result) => {
assert.equal($result.children().children()[0].childElementCount, 5, 'Five links in the drawer')
})
})
})
})
28 changes: 28 additions & 0 deletions cypress/integration/ambianic-tests/profile-menu.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference types="cypress" />

context('Profile menu', () => {
before(() => {
cy.visit('http://localhost:8080/timeline')
})

it('Should start authentication with Auth0', () => {
cy.get('[data-cy=display-profile]').click()

})

it('Confirm Profile Card Elements', () => {
cy.get('[data-cy=profile-toggle]').click()
cy.get('.v-list-item__title')
.should('contain.text', 'Test User')

cy.get('.v-list-item__subtitle')
.should('contain.text', 'test@gmail.com')

cy.get('[data-cy=logout-button]').should('be.visible')
})

it('Should open subscription modal', () => {
cy.get('[data-cy=add-subscription]').click()
cy.get('[data-cy=dismiss-modal]').click()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// <reference types="cypress" />

const checkViewPort = (cy, device) => {
export const checkViewPort = (cy, device) => {
cy.viewport(device)
cy.get('#toggle-visibility').should('be.visible')
cy.get('#peerId-container').should('be.visible')
Expand Down
35 changes: 35 additions & 0 deletions cypress/integration/ambianic-tests/subscription.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference types="cypress" />

context('SubscriptionModal', () => {
before(() => {
cy.visit('http://localhost:8080/timeline')
})

it('Should launch subscription modal', () => {
cy.get('[data-cy=auth-btn]').click()
})

it('It displays input fields', () => {
cy.get('[data-cy=subscribe]').click()

cy.get('[name=cardHolderName]').should('be.visible')
cy.get('[name=cardNumber]').should('be.visible')
cy.get('[name=emailAddress]').should('be.visible')
})

it('It validates card-number regex is functional', () => {
cy.get('[data-cy=confirm-btn]').should('be.disabled')

cy.get('[name=cardNumber]').type('4242424242424242')

cy.get('[data-cy=confirm-btn]').should('be.enabled')
})

it('It contains 7 input forms', () => {
cy.get('input').its('length').should('be.eq', 7)
})

it('should dismiss subscription modal', () => {
cy.get('[data-cy=dismiss-modal]').click()
})
})
8 changes: 8 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build]
command = "npm run build"
functions = "netlify/functions"

[[headers]]
for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"
18 changes: 18 additions & 0 deletions netlify/functions/cancelSubscription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require('dotenv').config()
const stripe = require('stripe')(process.env.STRIPE_TEST_KEY)

exports.handler = (event, context, callback) => {
const { stripeId } = event.queryStringParameters
stripe.subscriptions.del(stripeId).then(() => {
return callback(null, {
statusCode: 200,
body: JSON.stringify({ message: 'CUSTOMER HAS BEEN UNSUBSCRIBED' })
})
})
.catch(error => {
callback(null, {
statusCode: 422,
body: JSON.stringify({ message: 'ERROR GETTING CUSTOMERS', error })
})
})
}
25 changes: 25 additions & 0 deletions netlify/functions/getCustomers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require('dotenv').config()
const stripe = require('stripe')(process.env.STRIPE_TEST_KEY)

const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'
}

exports.handler = (event, context, callback) => {
stripe.customers
.list()
.then(customers => {
return callback(null, {
statusCode: 200,
headers,
body: JSON.stringify({ customers })
})
})
.catch(error => callback(null, {
statusCode: 422,
headers,
body: JSON.stringify({ message: 'ERROR GETTING CUSTOMERS', error })
}))
}
66 changes: 66 additions & 0 deletions netlify/functions/subscriptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require('dotenv').config()
const stripe = require('stripe')(process.env.STRIPE_TEST_KEY)

const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'
}

// TODO: Refactor to use async await.
exports.handler = (event, context, callback) => {
const { email, card } = event.queryStringParameters

// eslint-disable-next-line camelcase
const { number, cvc, exp_month, exp_year } = JSON.parse(card)

stripe.sources.create({
type: 'ach_credit_transfer',
currency: 'usd',
owner: {
email
}
}, (err, source) => {
if (err) {
console.log(err)
}
// Create a payment method for user using the Card Details
stripe.paymentMethods.create({
type: 'card',
card: {
number, cvc, exp_year, exp_month
}
}).then(({ id: paymentID }) => {
// Creates Customer ==>
stripe.customers
.create({
email,
description: 'Ambianic customer using premium service',
payment_method: paymentID,
source: source.id
})
.then(({ id: customerID }) => {
stripe.paymentMethods.attach(paymentID, { customer: customerID }).then((data) => {
stripe.subscriptions.create({
customer: customerID,
items: [{
price: process.env.EMAIL_PRODUCT_ID
}]
}).then(() => callback(null, {
statusCode: 200,
headers,
body: JSON.stringify({ message: 'EMAIl SUBSCRIPTION CREATED' })
})).catch(e => {
console.log(`Err creating subscription : ${e}`)
})
}).catch(e => {
console.log(`Creating customer ${e}`)
})
})
}).catch(error => callback(null, {
statusCode: 422,
headers,
body: JSON.stringify({ message: 'ERROR CREATING USER', error })
}))
})
}
9 changes: 9 additions & 0 deletions netlify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "functions",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"stripe": "^8.135.0"
}
}
Loading

0 comments on commit bd85dfe

Please sign in to comment.