Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 3 additions & 38 deletions cypress/e2e/index.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { refreshToken } from '../../src/spotify/auth/refreshToken';

describe('index', () => {
it('displays login button when user is not logged in', () => {
cy.visit('https://d1e7htx1c4j3w0.cloudfront.net/');
Expand Down Expand Up @@ -50,37 +48,15 @@ describe('index', () => {
});

it('displays username when user is logged in', () => {
cy.wrap(null).then(async () => {
process.env.SPOTIFY_CLIENT_ID = Cypress.env('SPOTIFY_CLIENT_ID');
process.env.SPOTIFY_CLIENT_SECRET = Cypress.env('SPOTIFY_CLIENT_SECRET');
process.env.AUTH_REDIRECT_URI = Cypress.env('AUTH_REDIRECT_URI');
process.env.CREATE_PLAYLIST_LAMBDA_ARN = Cypress.env(
'CREATE_PLAYLIST_LAMBDA_ARN'
);
const accessToken = await refreshToken(
Cypress.env('TEST_USER_REFRESH_TOKEN')
);
cy.setCookie('access_token', accessToken);
});
cy.loginAsTestUser();

cy.visit(`https://d1e7htx1c4j3w0.cloudfront.net/`);

cy.contains('all-tracks-test-user');
});

it('hides login button when user is logged in', () => {
cy.wrap(null).then(async () => {
process.env.SPOTIFY_CLIENT_ID = Cypress.env('SPOTIFY_CLIENT_ID');
process.env.SPOTIFY_CLIENT_SECRET = Cypress.env('SPOTIFY_CLIENT_SECRET');
process.env.AUTH_REDIRECT_URI = Cypress.env('AUTH_REDIRECT_URI');
process.env.CREATE_PLAYLIST_LAMBDA_ARN = Cypress.env(
'CREATE_PLAYLIST_LAMBDA_ARN'
);
const accessToken = await refreshToken(
Cypress.env('TEST_USER_REFRESH_TOKEN')
);
cy.setCookie('access_token', accessToken);
});
cy.loginAsTestUser();

cy.visit(`https://d1e7htx1c4j3w0.cloudfront.net/`);

Expand All @@ -91,18 +67,7 @@ describe('index', () => {
});

it("informs user playlist will be available soon when 'Create Playlist' is clicked", () => {
cy.wrap(null).then(async () => {
process.env.SPOTIFY_CLIENT_ID = Cypress.env('SPOTIFY_CLIENT_ID');
process.env.SPOTIFY_CLIENT_SECRET = Cypress.env('SPOTIFY_CLIENT_SECRET');
process.env.AUTH_REDIRECT_URI = Cypress.env('AUTH_REDIRECT_URI');
process.env.CREATE_PLAYLIST_LAMBDA_ARN = Cypress.env(
'CREATE_PLAYLIST_LAMBDA_ARN'
);
const accessToken = await refreshToken(
Cypress.env('TEST_USER_REFRESH_TOKEN')
);
cy.setCookie('access_token', accessToken);
});
cy.loginAsTestUser();

cy.visit(`https://d1e7htx1c4j3w0.cloudfront.net/`);

Expand Down
41 changes: 16 additions & 25 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import { refreshToken } from '../../src/spotify/auth/refreshToken';

Cypress.Commands.add('loginAsTestUser', () => {
cy.wrap(null).then(async () => {
process.env.SPOTIFY_CLIENT_ID = Cypress.env('SPOTIFY_CLIENT_ID');
process.env.SPOTIFY_CLIENT_SECRET = Cypress.env('SPOTIFY_CLIENT_SECRET');
process.env.AUTH_REDIRECT_URI = Cypress.env('AUTH_REDIRECT_URI');
process.env.CREATE_PLAYLIST_LAMBDA_ARN = Cypress.env(
'CREATE_PLAYLIST_LAMBDA_ARN'
);
const accessToken = await refreshToken(
Cypress.env('TEST_USER_REFRESH_TOKEN')
);
cy.setCookie('access_token', accessToken);
});
});