Skip to content

Commit

Permalink
Merge branch 'beta' into normalize-aggregate-error
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Jan 12, 2021
2 parents 3bf0a2a + 6557001 commit 494e70c
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 82 deletions.
4 changes: 3 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"viewportHeight": 1000,
"fixturesFolder": false,
"pluginsFile": false,
"supportFile": false,
"reporter": "junit",
"reporterOptions": {
"mochaFile": "test-results/cypress/junit-[hash].xml"
},
"retries": {
"runMode": 3
}
}
41 changes: 18 additions & 23 deletions cypress/integration/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,36 @@ if (!EMAIL || !PASSWORD) {
throw new Error('You must provide CYPRESS_USER_EMAIL and CYPRESS_USER_PASSWORD environment variables');
}

const loginToAuth0 = (): void => {
cy.visit('/');
cy.get('#login').click();
cy.get('.auth0-lock-input-email input').focus().clear().type(EMAIL);
cy.get('.auth0-lock-input-password input').focus().clear().type(PASSWORD);
cy.get('.auth0-lock-submit').click();
};
describe('smoke tests', () => {
before(() => {
cy.visit('/');
cy.get('[data-testid=login]').click();
cy.get('input[name=email], input[name=username]').focus().clear().type(EMAIL);
cy.get('input[name=password]').focus().clear().type(PASSWORD);
cy.get('button[name=submit], button[name=action]').click();
});

describe('Smoke tests', () => {
it('should do basic login and show user', () => {
loginToAuth0();

cy.url().should('eq', `${Cypress.config().baseUrl}/`);
cy.get('#profile').contains(EMAIL);
cy.get('#logout').click();
cy.get('#login').should('exist');
cy.get('[data-testid=profile]').contains(EMAIL);
cy.get('[data-testid=logout]').should('exist');
});

it('should protect a client-side rendered page', () => {
loginToAuth0();

cy.url().should('eq', `${Cypress.config().baseUrl}/`);
cy.visit('/profile');
cy.url().should('eq', `${Cypress.config().baseUrl}/profile`);
cy.get('#profile').contains(EMAIL);
cy.get('#logout').click();
cy.get('[data-testid=profile]').contains(EMAIL);
});

it('should protect a server-side-rendered page', () => {
loginToAuth0();

cy.url().should('eq', `${Cypress.config().baseUrl}/`);
cy.visit('/profile-ssr');
cy.url().should('eq', `${Cypress.config().baseUrl}/profile-ssr`);
cy.get('#profile').contains(EMAIL);
cy.get('#logout').click();
cy.get('[data-testid=profile]').contains(EMAIL);
});

it('should logout and return to the index page', () => {
cy.get('[data-testid=logout]').click();
cy.url().should('eq', `${Cypress.config().baseUrl}/`);
cy.get('[data-testid=login]').should('exist');
});
});
3 changes: 3 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Cypress.Cookies.defaults({
preserve: () => true
});
37 changes: 18 additions & 19 deletions examples/basic-example/components/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from 'next/link';
import { useUser } from '@auth0/nextjs-auth0';

const Header = () => {
const { user, isLoading } = useUser();
const { user } = useUser();

return (
<header>
Expand All @@ -19,24 +19,23 @@ const Header = () => {
<a>Protected Page</a>
</Link>
</li>
{!isLoading &&
(user ? (
<>
<li>
<a href="/api/auth/logout" id="logout">
Logout
</a>
</li>
</>
) : (
<>
<li>
<a href="/api/auth/login" id="login">
Login
</a>
</li>
</>
))}
{user ? (
<>
<li>
<a href="/api/auth/logout" data-testid="logout">
Logout
</a>
</li>
</>
) : (
<>
<li>
<a href="/api/auth/login" data-testid="login">
Login
</a>
</li>
</>
)}
</ul>
</nav>

Expand Down
2 changes: 1 addition & 1 deletion examples/basic-example/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Home() {
{user && (
<>
<h4>Rendered user info on the client</h4>
<pre id="profile">{JSON.stringify(user, null, 2)}</pre>
<pre data-testid="profile">{JSON.stringify(user, null, 2)}</pre>
</>
)}

Expand Down
55 changes: 27 additions & 28 deletions examples/kitchen-sink-example/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import Link from 'next/link';
import { useUser } from '@auth0/nextjs-auth0';

const Header: React.FunctionComponent = () => {
const { user, isLoading } = useUser();
const Header = (): React.ReactElement => {
const { user } = useUser();

return (
<header>
Expand All @@ -24,32 +24,31 @@ const Header: React.FunctionComponent = () => {
<a>TV Shows</a>
</Link>
</li>
{!isLoading &&
(user ? (
<>
<li>
<Link href="/profile">
<a>Profile</a>
</Link>
</li>{' '}
<li>
<a href="/profile-ssr">Profile (SSR)</a>
</li>{' '}
<li>
<a href="/api/auth/logout" id="logout">
Logout
</a>
</li>
</>
) : (
<>
<li>
<a href="/api/auth/login" id="login">
Login
</a>
</li>
</>
))}
{user ? (
<>
<li>
<Link href="/profile">
<a>Profile</a>
</Link>
</li>{' '}
<li>
<a href="/profile-ssr">Profile (SSR)</a>
</li>{' '}
<li>
<a href="/api/auth/logout" data-testid="logout">
Logout
</a>
</li>
</>
) : (
<>
<li>
<a href="/api/auth/login" data-testid="login">
Login
</a>
</li>
</>
)}
</ul>
</nav>

Expand Down
4 changes: 1 addition & 3 deletions examples/kitchen-sink-example/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import Head from 'next/head';

import Header from './header';

type LayoutProps = React.PropsWithChildren<{}>;

const Layout: React.FunctionComponent<LayoutProps> = ({ children }: LayoutProps) => (
const Layout = ({ children }: React.PropsWithChildren<unknown>): React.ReactElement => (
<>
<Head>
<title>Next.js with Auth0</title>
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@auth0/nextjs-auth0": "file:../../",
"@serverless-jwt/next": "^0.2.0",
"@serverless-jwt/next": "^0.2.1",
"next": "file:../../node_modules/next",
"react": "file:../../node_modules/react",
"react-dom": "file:../../node_modules/react-dom"
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink-example/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Home(): React.ReactElement {
{user && (
<>
<h4>Rendered user info on the client</h4>
<pre id="profile">{JSON.stringify(user, null, 2)}</pre>
<pre data-testid="profile">{JSON.stringify(user, null, 2)}</pre>
</>
)}

Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink-example/pages/profile-ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Profile({ user }: ProfileProps): React.ReactElement {

<div>
<h3>Profile (server rendered)</h3>
<pre id="profile">{JSON.stringify(user, null, 2)}</pre>
<pre data-testid="profile">{JSON.stringify(user, null, 2)}</pre>
</div>
</Layout>
);
Expand Down
2 changes: 1 addition & 1 deletion examples/kitchen-sink-example/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default withPageAuthRequired(function Profile(): React.ReactElement {
{user && (
<>
<h4>Profile</h4>
<pre id="profile">{JSON.stringify(user, null, 2)}</pre>
<pre data-testid="profile">{JSON.stringify(user, null, 2)}</pre>
</>
)}
</Layout>
Expand Down
8 changes: 5 additions & 3 deletions examples/kitchen-sink-example/pages/shows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import useApi from '../lib/use-api';
import Layout from '../components/layout';
import { withPageAuthRequired } from '@auth0/nextjs-auth0';

type TVShow = { show: { name: string } };

export default withPageAuthRequired(function TvShows(): React.ReactElement {
const { response, error, isLoading } = useApi('/api/shows');

Expand All @@ -13,20 +15,20 @@ export default withPageAuthRequired(function TvShows(): React.ReactElement {

{isLoading && <p>Loading TV shows...</p>}

{!isLoading && response && (
{response && (
<>
<p>My favourite TV shows:</p>
<pre>
{JSON.stringify(
response.shows.map((s) => s.show.name),
response.shows.map((s: TVShow) => s.show.name),
null,
2
)}
</pre>
</>
)}

{!isLoading && error && (
{error && (
<>
<p>Error loading TV shows</p>
<pre style={{ color: 'red' }}>{JSON.stringify(error, null, 2)}</pre>
Expand Down

0 comments on commit 494e70c

Please sign in to comment.