Skip to content

Commit

Permalink
Update cookie name/tests, test on develop server
Browse files Browse the repository at this point in the history
- weird bug where the backend sets the cookie in the frontend with _WebsiteOne_session that is malformed so changed them all to WebsiteOne_session instead
- develop server on azure runs in production environment
  • Loading branch information
mattwr18 committed Apr 25, 2019
1 parent 4cf4529 commit 6e202dc
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/actions/createBillingAgreement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (cookies, id, dispatch) => event => {
plan: id
},
headers: {
Authorization: cookies.get('_WebsiteOne_session')
Authorization: cookies.get('WebsiteOne_session')
}
})
.then(response => window.location.assign(response.data.redirect_url))
Expand Down
2 changes: 1 addition & 1 deletion src/actions/createEventAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export let createEvent = props => dispatch => {
} = props
return axios({
method: 'POST',
url: 'http://localhost:3000/events',
url: '/events',
data: {
event: {
name,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/createProjectAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export let createProject = props => dispatch => {
}
},
headers: {
Authorization: cookies.get('_WebsiteOne_session'),
Authorization: cookies.get('WebsiteOne_session'),
Accept: 'application/json'
}
}).then(response => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/createStripeSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (cookies, email, id, dispatch, slug) => {
plan: slug
},
headers: {
Authorization: cookies.get('_WebsiteOne_session')
Authorization: cookies.get('WebsiteOne_session')
}
})
.catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/executeBillingAgreement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (cookies, params, dispatch) => {
token: params.token
},
headers: {
Authorization: cookies.get('_WebsiteOne_session')
Authorization: cookies.get('WebsiteOne_session')
}
})
.catch(error => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ProjectsList from '../containers/ProjectsList'
import ProjectInfo from '../containers/ProjectInfo'
import Homepage from '../components/Homepage'
import Footer from '../components/Footer'
import Navbar from './navbar/Navbar'
import Navbar from './Navbar'
import About from '../containers/About'
import LogIn from '../containers/LogIn'
import SignUp from '../containers/SignUp'
Expand Down
15 changes: 4 additions & 11 deletions src/components/navbar/Navbar.js → src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@ import React, { Component, Fragment } from 'react'
import { Menu, Container, Image, Icon } from 'semantic-ui-react'
import { Link } from 'react-router-dom'
import { withRouter } from 'react-router'
import logo from '../../images/av-logo.svg'
import logo from '../images/av-logo.svg'
import queryString from 'query-string'

import './Navbar.css'
import '../assets/Navbar.css'

export class Navbar extends Component {
state = { showHamburgerMenu: false, isLoggedIn: false }
componentDidMount () {
const parsed = queryString.parse(this.props.location.search)
if (parsed.token) {
this.props.cookies.set('OAuth_session', `Bearer ${parsed.token}`, {
this.props.cookies.set('WebsiteOne_session', parsed.token, {
path: '/'
})
this.setState({ isLoggedIn: true })
}
}

componentWillReceiveProps (nextProps) {
if (this.props.cookies.get('WebsitOne_session') !== nextProps.cookies.get('WebsiteOne_session')) {
this.setState({ isLoggedIn: true })
}
}

currentPath () {
// this.props.location.split("/") returns ["", ""] when on homepage
// and ["", "users", "123"] when on /users/123
Expand All @@ -35,7 +29,6 @@ export class Navbar extends Component {

handleRemoveCookies = () => {
this.setState({ isLoggedIn: false })
this.props.cookies.remove('OAuth_session')
this.props.cookies.remove('WebsiteOne_session')
}

Expand Down Expand Up @@ -87,7 +80,7 @@ export class Navbar extends Component {
>
<Link to='/getting-started'>Getting Started</Link>
</Menu.Item>
{isLoggedIn || cookies.get('OAuth_session') || cookies.get('WebsiteOne_session') ? (
{isLoggedIn || cookies.get('WebsiteOne_session') ? (
<Menu.Item name='signout' active={activeItem === 'signout'}>
<Link to='/' onClick={this.handleRemoveCookies}>
<Icon name='sign-out' />
Expand Down
4 changes: 2 additions & 2 deletions src/containers/CreateEventPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CreateEventPage extends Component {
componentDidMount () {
const path = this.props.location.pathname
this.props.setLastLocation(path)
if (!this.props.cookies.get('_WebsiteOne_session') && !this.props.loggedInUser.data) {
if (!this.props.cookies.get('WebsiteOne_session') && !this.props.loggedInUser.data) {
this.props.history.push({ pathname: '/login' })
}
if (!this.props.projects.length) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export class CreateEventPage extends Component {
const startDateFormatted = moment(startDate).format('YYYYMMDD')
const weekdaysLowerCase = weekdays.map(day => day.toLowerCase())
const { history, createEvent } = this.props
const headers = this.props.cookies.get('_WebsiteOne_session')
const headers = this.props.cookies.get('WebsiteOne_session')
createEvent({
headers,
history,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Subscriptions = props => {
const path = props.location.pathname
const search = props.location.search
props.setLastLocation(path, search)
if (!props.cookies.get('_WebsiteOne_session') && !props.loggedInUser.data) {
if (!props.cookies.get('WebsiteOne_session') && !props.loggedInUser.data) {
props.history.push({ pathname: '/login' })
}
if (props.error.length) {
Expand Down
25 changes: 21 additions & 4 deletions src/tests/components/Navbar.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { mount } from 'enzyme'
import { BrowserRouter as Router } from 'react-router-dom'
import { Navbar } from '../../components/navbar/Navbar'
import { Navbar } from '../../components/Navbar'

describe('Navbar', () => {
let wrapper
const props = {
location: { pathname: '/users' },
cookies: { get: jest.fn(), remove: jest.fn() }
location: { pathname: '/users', search: '' },
cookies: { get: jest.fn(), remove: jest.fn(), set: jest.fn() }
}

beforeEach(() => {
Expand Down Expand Up @@ -64,7 +64,24 @@ describe('Navbar', () => {
return item.text() === 'Log out'
})
logOutLink.simulate('click')
expect(props.cookies.remove).toHaveBeenCalledTimes(2)
expect(props.cookies.remove).toHaveBeenCalledTimes(1)
})

it('sets the cookies if their is a token in the url search', () => {
props.location.search = '?token=WebsiteOne_session'
mount(
<Router>
<Navbar {...props} />
</Router>
)
expect(props.cookies.set).toHaveBeenCalledTimes(1)
})

it('toggles showHamberMenu when user click on the hamburger icon', () => {
const navbar = wrapper.find('Navbar')
const hamburgerIcon = wrapper.find('.hamburger')
hamburgerIcon.simulate('click')
expect(navbar.state().showHamburgerMenu).toEqual(true)
})
})
})
18 changes: 18 additions & 0 deletions src/tests/containers/LogIn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mount } from 'enzyme'

describe('LogIn', () => {
let wrapper
const { assign } = window.location
const user = {
id: 1,
email: 'existing-user@example.com',
Expand All @@ -29,6 +30,14 @@ describe('LogIn', () => {
}
beforeEach(() => {
wrapper = mount(<LogIn {...props} />)
Object.defineProperty(window.location, 'assign', {
configurable: true
})
window.location.assign = jest.fn()
})

afterEach(() => {
window.location.assign = assign
})

it('returns the user if postLogInInfo is called with the correct credentials', async () => {
Expand Down Expand Up @@ -145,4 +154,13 @@ describe('LogIn', () => {
expect(props.history.push).toHaveBeenCalledWith('/events/new')
})
})

it('redirects to login via github oauth when clickin on login with github', () => {
// console.log(wrapper.debug())
const oauthLogInButton = wrapper.find('button').filterWhere(item => {
return item.text() === 'with GitHub'
})
oauthLogInButton.simulate('click')
expect(window.location.assign).toBeCalledTimes(1)
})
})
8 changes: 0 additions & 8 deletions src/utils.js

This file was deleted.

0 comments on commit 6e202dc

Please sign in to comment.