Skip to content

Commit

Permalink
Added cypress + pages/new.js redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
optimista committed Jun 6, 2021
1 parent 5a30f1d commit 06e16da
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
6 changes: 6 additions & 0 deletions fb/bin/fb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ case $1 in
gcloud iam service-accounts keys create /tmp/keys --iam-account=$iamaccount
keysbase64="$( cat /tmp/keys | base64 )" # Is used at the ending prompts

# CYPRESS INSTALL & CONFIGURATION
npm install cypress --save-dev
cp $dir/src/cypress.json .
cp -r $dir/src/cypress .
sed -i '' "s/\(^\/coverage\)/\1\n\/cypress\/screenshots\n\/cypress\/videos/g" .gitignore

## MAIN
npm install uuid
cp $dir/src/next.config.js .
Expand Down
3 changes: 3 additions & 0 deletions fb/src/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}
100 changes: 100 additions & 0 deletions fb/src/cypress/integration/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
describe('pages/', () => {
context('[username].js', () => {
it('works', () => cy.visit("/random"))
context('if user does not exist', () => {
it('redirects to /index.js', () => {
cy.visit('/random');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/');
})
})
})

context('user with username "optimistavf" does exist', () => {
it('contains @optimistavf', () => {
cy.visit('/optimistavf');
cy.contains("@optimistavf");
})
})
});

context('account/reset.js', () => {
it('works', () => cy.visit("/account/reset"))
});

context('account/confirm.js', () => {
it('works', () => cy.visit("/account/confirm"))
context('if not provided oobCode', () => {
it('redirects to /account/reset.js', () => {
cy.visit('/account/confirm');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/account/reset');
})
})
})
});

context('index.js', () => {
it('works', () => cy.visit("/"))
});

context('join.js', () => {
it('works', () => cy.visit("/join"))
});

context('login.js', () => {
it('works', () => cy.visit("/login"))
});

context('new.js', () => {
it('works', () => cy.visit("/new"))
context('if user is not logged in', () => {
it('redirects to /index.js', () => {
cy.visit('/new');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/');
})
})
})
});

context('s/[id].js', () => {
it('works', () => cy.visit("/s/random"));
context('if story does not exist', () => {
it('redirects to /index.js', () => {
cy.visit('/s/random');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/');
})
})
})
});

context('s/[id]/edit.js', () => {
it('works', () => cy.visit("/s/random/edit"));
context('if story does not exist', () => {
it('redirects to /index.js', () => {
cy.visit('/s/random/edit');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/');
})
})
})
});

context('stories.js', () => {
it('works', () => cy.visit("/stories"))
context('if user is not logged in', () => {
it('redirects to /index.js', () => {
cy.visit('/stories');
cy.location().should(loc => {
expect(loc.pathname).to.eq('/');
})
})
})
});

context('theme.js', () => {
it('works', () => cy.visit("/theme"))
});
})
4 changes: 2 additions & 2 deletions fb/src/pages/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const StoryNewPage = () => {
auth = useAuth(), router = useRouter(), { id } = router.query,
autosave = useAutosave({ query: () => Stories.doc(id).set(state.story) });

useEffect(() => auth.isReady &&
useEffect(() => auth.isReady && (auth.isLoggedIn ?
Stories.add({ ...state.story, profileId: auth.uid }).then(doc => router.replace(storyEditPath(doc), null, { shallow: true })) &&
dispatch(state => ({ type: "STORY_LOAD", value: { ...state.story, profileId: auth.uid } }))
dispatch(state => ({ type: "STORY_LOAD", value: { ...state.story, profileId: auth.uid } })) : router.replace("/"))
, [auth.isReady]);

return (
Expand Down

0 comments on commit 06e16da

Please sign in to comment.