The "Book Library" web application is a Single Page Application (SPA) built with JavaScript. It dynamically updates its content based on user interactions and supports user profiles along with CRUD operations through a RESTful service.
- Guests (un-authenticated users) can access links to All Books, Login, and Register pages.
- Authenticated users can see links to All Books, My Books, Add Book, a welcome message with the user's email, and a Logout link.
The provided REST service includes pre-configured user accounts for testing purposes. The Login page features a form for authenticating existing users by entering an email and password. The app checks for empty fields before attempting to log in. If the login is successful, the REST service returns an object with a generated _id
and an accessToken
for the session. This token is saved in sessionStorage
to authorize subsequent requests. Upon success, the user is redirected to the All Books/Dashboard page. If there’s an error or validation fails, an alert displays an error message.
New users can register by providing an email and password. All fields must be filled, or an error is shown. A successful registration returns an object with a generated _id
and an accessToken
. After registering, users are redirected to the All Books/Dashboard page. Errors or validation failures trigger an error alert.
Available to authenticated users. Logging out redirects the user to the All Books/Dashboard page.
Logged-in users can access the Add Book page, which includes a form for creating a new book. The app checks that all fields are filled before submission. A successful addition returns the new book record and redirects the user to the All Books/Dashboard page.
This page displays a list of all books in the system. Clicking on the details button leads to the details page for the selected book. Visible to guests and logged-in users.
The All Books page lists all books in the system. Both guests and logged-in users can access this page. Selecting a book takes the user to its details page.
All users can view detailed information about each book. Logged-in users who own the book see options to edit or delete it.
This feature allows logged-in users to edit their books. The app checks that all fields are filled before submission. A successful edit returns the updated book and redirects the user to its details page.
Logged-in users can delete books they own. A confirmation prompt appears before deletion. Upon confirmation, the book is removed from the system, and the user is redirected to the All Books/Dashboard page.
Authenticated users can view a list of books they’ve added by clicking [My Books].
- Method: GET
- Endpoint: /data/books?where=_ownerId%3D%22{userId}%22&sortBy=_createdOn%20desc
Authenticated users can like other users' books, but not their own. Clicking [Like] increases the book's like count by 1.
- Method: GET
- URL: /data/likes?where=bookId%3D%22{bookId}%22&distinct=_ownerId&count
- Method: GET
- URL: /data/likes?where=bookId%3D%22{bookId}%22%20and%20_ownerId%3D%22{userId}%22&count
To initialize the SPA, run the following commands in the terminal within Visual Studio Code:
npm install
This command installs the Playwright framework and http-server.
- Start the server by running:
npm run start
- This should open the app's homepage in a web browser.
- Then, open a separate terminal and execute:
npm run server
- Create a new folder named
tests
, and within it, create a file namedui.test.js
. This file will contain the UI tests, written using Playwright and@playwright/test
.
To execute the Playwright tests, open a new terminal in Visual Studio Code and run:
npm run test
Contributions are welcome! If you have any improvements or bug fixes, feel free to open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, please open an issue in the repository.