Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11-sifers #10

Open
wants to merge 1 commit into
base: 10-error-loading-books
Choose a base branch
from
Open
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
58 changes: 31 additions & 27 deletions projects/earnings-app-e2e/src/integration/books-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,47 @@ import * as BookListComponent from '../support/book-list-component.harness';
import * as BookFormComponent from '../support/book-form-component.harness';
import * as BooksPage from '../support/books-page.harness';

describe('Books Page', () => {
let book: BookModel;

beforeEach(() => {
book = {
id: uuid.v4(),
name: 'The Lord of the Rings',
earnings: '100',
description:
'The Lord of the Rings is an epic high fantasy novel written by English author and scholar J. R. R. Tolkien.',
};

BooksApi.deleteAllBooks();
BooksApi.createBook(book);

function setup(options: { throwErrorWhenLoadingBooks?: boolean } = {}) {
const book = {
id: uuid.v4(),
name: 'The Lord of the Rings',
earnings: '100',
description:
'The Lord of the Rings is an epic high fantasy novel written by English author and scholar J. R. R. Tolkien.',
};

BooksApi.deleteAllBooks();
BooksApi.createBook(book);

if (options.throwErrorWhenLoadingBooks) {
cy.intercept('GET', 'http://localhost:3000/books', {
statusCode: 500,
body: {
error: 'Internal Server Error',
},
}).as('getBooks');
} else {
cy.intercept('GET', 'http://localhost:3000/books').as('getBooks');
}

AuthApi.login('Admin', 'password');
AuthApi.login('Admin', 'password');

cy.visit('/');
cy.visit('/');

cy.wait('@getBooks');
});
cy.wait('@getBooks');

return book;
}

describe('Books Page', () => {
it('should show a list all of the books', () => {
const book = setup();

BookListComponent.getBook(book.id).should('contain', book.name);
});

it('should gracefully show an error message when loading the books fails', () => {
cy.intercept('GET', 'http://localhost:3000/books', {
statusCode: 500,
body: {
error: 'Internal Server Error',
},
}).as('getBooks');
cy.visit('/');
cy.wait('@getBooks');
setup({ throwErrorWhenLoadingBooks: true });

BooksPage.getError().should('contain', 'Error');
});
Expand Down