-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for authentication, refactor
- Loading branch information
Showing
12 changed files
with
154 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import { ITEM_TYPES } from '../../src/config/constants'; | ||
|
||
export const MEMBERS = { | ||
ANNA: { id: 'anna-id', name: 'anna', email: '[email protected]' }, | ||
BOB: { id: 'bob-id', name: 'bob', email: '[email protected]' }, | ||
}; | ||
|
||
export const CURRENT_USER_ID = MEMBERS.ANNA.id; | ||
import { CURRENT_USER } from './members'; | ||
|
||
const DEFAULT_ITEM = { | ||
description: '', | ||
extra: {}, | ||
creator: CURRENT_USER_ID, | ||
creator: CURRENT_USER.id, | ||
type: ITEM_TYPES.SPACE, | ||
}; | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const MEMBERS = { | ||
ANNA: { id: 'anna-id', name: 'anna', email: '[email protected]' }, | ||
BOB: { id: 'bob-id', name: 'bob', email: '[email protected]' }, | ||
}; | ||
|
||
export const CURRENT_USER = MEMBERS.ANNA; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
buildItemPath, | ||
HOME_PATH, | ||
SHARED_ITEMS_PATH, | ||
} from '../../src/config/paths'; | ||
import { | ||
HEADER_APP_BAR_ID, | ||
HEADER_USER_ID, | ||
USER_MENU_SIGN_OUT_OPTION_ID, | ||
} from '../../src/config/selectors'; | ||
import { SAMPLE_ITEMS } from '../fixtures/items'; | ||
import { CURRENT_USER } from '../fixtures/members'; | ||
|
||
const PAGE_LOAD_WAITING_TIME = 3000; | ||
|
||
describe('Authentication', () => { | ||
describe('Signed Off > Redirect to sign in route', () => { | ||
beforeEach(() => { | ||
cy.setUpApi({ items: SAMPLE_ITEMS, getCurrentMemberError: true }); | ||
}); | ||
it('Home', () => { | ||
cy.visit(HOME_PATH); | ||
cy.wait('@signInRedirection'); | ||
}); | ||
it('Shared Items', () => { | ||
cy.visit(SHARED_ITEMS_PATH); | ||
cy.wait('@signInRedirection'); | ||
}); | ||
it('Item', () => { | ||
cy.visit(buildItemPath(SAMPLE_ITEMS[0].id)); | ||
cy.wait('@signInRedirection'); | ||
}); | ||
}); | ||
|
||
describe('Signed In', () => { | ||
beforeEach(() => { | ||
cy.setUpApi({ items: SAMPLE_ITEMS }); | ||
}); | ||
|
||
it('Signing Off redirect to sign in route', () => { | ||
cy.visit(HOME_PATH); | ||
// user name in header | ||
cy.get(`#${HEADER_USER_ID}`).click(); | ||
cy.get(`#${USER_MENU_SIGN_OUT_OPTION_ID}`).click(); | ||
cy.wait('@signInRedirection'); | ||
}); | ||
|
||
describe('Load page correctly', () => { | ||
it('Home', () => { | ||
cy.visit(HOME_PATH); | ||
cy.wait(PAGE_LOAD_WAITING_TIME); | ||
cy.get(`#${HEADER_APP_BAR_ID}`).should('exist'); | ||
}); | ||
it('Shared Items', () => { | ||
cy.visit(SHARED_ITEMS_PATH); | ||
cy.wait(PAGE_LOAD_WAITING_TIME); | ||
cy.get(`#${HEADER_APP_BAR_ID}`).should('exist'); | ||
}); | ||
it('Item', () => { | ||
cy.visit(buildItemPath(SAMPLE_ITEMS[0].id)); | ||
cy.wait(PAGE_LOAD_WAITING_TIME); | ||
cy.get(`#${HEADER_APP_BAR_ID}`).should('exist'); | ||
}); | ||
}); | ||
|
||
describe('Display User Information', () => { | ||
it('Header', () => { | ||
cy.visit(HOME_PATH); | ||
// user name in header | ||
cy.get(`#${HEADER_USER_ID}`).should('contain', CURRENT_USER.name); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { API_HOST } from '../config/constants'; | ||
import { SIGN_OUT_ROUTE } from './routes'; | ||
import { DEFAULT_GET, checkRequest } from './utils'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const signOut = async () => { | ||
const req = await fetch(`${API_HOST}/logout`, DEFAULT_GET).then(checkRequest); | ||
const req = await fetch(`${API_HOST}/${SIGN_OUT_ROUTE}`, DEFAULT_GET).then( | ||
checkRequest, | ||
); | ||
return req.ok; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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