Skip to content

Development #191

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
191d2a4
New function names to queries and mocks, added reservation tests
Juho9 Nov 16, 2023
3731de2
favorite_book jest
Juho9 Nov 16, 2023
269dcdb
book_review jest
Juho9 Nov 16, 2023
22614f8
book_request jest with updated function names
Juho9 Nov 16, 2023
996ec26
office jest
Juho9 Nov 16, 2023
828fd8a
borrow robot tests
Juho9 Nov 21, 2023
79b3c4a
modified typo and wrong status at borrow_test
Juho9 Nov 21, 2023
0187c37
removed admin tests from borrow
Juho9 Nov 21, 2023
b63de01
Merge branch 'development' into jest-testing
Juho9 Nov 21, 2023
d10b4eb
robottests for booklist and favorites
Juho9 Nov 21, 2023
18a1fab
added tests for bookreviews and fixed typo on booklists
Juho9 Nov 21, 2023
8eac67d
tests for request and reservation
Juho9 Nov 22, 2023
5a5b7eb
corrected status and requests
Juho9 Nov 22, 2023
a0eecf7
Fixed adding new reservation test
Juho9 Nov 22, 2023
65d1aed
fixed wrong id in book reservation-tests
Juho9 Nov 22, 2023
3191629
id back to bookid
Juho9 Nov 22, 2023
8ebc8be
correct expected contents
Juho9 Nov 22, 2023
3f9aab8
Added new workflow and compose to push docker image using alpine and …
jounijoh Nov 23, 2023
f3574c6
Added new workflow and compose to push docker image using alpine and …
jounijoh Nov 23, 2023
912f30d
Fixed favorite test missing json-data
Juho9 Nov 24, 2023
c0e8d71
changes testdata to use real books that exist in google books api
Cisse23 Nov 25, 2023
482010e
Merge pull request #184 from LibraryProjectGroup/s23-real-books
samz9n Nov 27, 2023
6bfe88d
books do not disappear if its office is removed & added function for …
wilbuuuur Nov 27, 2023
f71709b
Changed ghcr image to be build with node:16-bullseye
jounijoh Nov 28, 2023
481abb0
Merge pull request #182 from LibraryProjectGroup/jest-testing
Lauri-Iivarinen Nov 29, 2023
5d0dd8a
Merge pull request #186 from LibraryProjectGroup/s23-docker-compose-t…
Lauri-Iivarinen Nov 29, 2023
1e398e4
changed book_reservations cancel and loan request body to reservationId
Nov 29, 2023
9e30ec7
check if book is reserved when adding loan
Nov 29, 2023
063668e
merged changes from development
Nov 29, 2023
6298f5f
Fixed tests
Juho9 Nov 29, 2023
2e6fc0b
Fixed formatting?
Juho9 Nov 29, 2023
959b4bf
Merge pull request #189 from LibraryProjectGroup/s23-bookreservation-fix
Lauri-Iivarinen Nov 30, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy backend to staging

on:
push:
branches: ['development', 'gh-actions', 's23-docker-compose-tests']
branches: ['development', 'gh-actions', s23-docker-compose-tests]

env:
REGISTRY: ghcr.io
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build
FROM node:alpine as builder
FROM node:16-bullseye as builder

WORKDIR /app

Expand All @@ -14,10 +14,12 @@ COPY . .
RUN npm run build

# Stage 2: Run
FROM node:alpine
FROM node:16-bullseye

WORKDIR /app

# Copy SQL scripts for database initialization MAYBE NOT NEEDED in production/staging
COPY sql /app/sql
# Copy built assets from builder stage
COPY --from=builder /app/build ./build
# Only copy the necessary files for runtime
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ services:
image: ${IMAGE_NAME}
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.staging
ports:
- 3002:3002
2 changes: 2 additions & 0 deletions robot/common.resource
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ ${BACKENDTESTPASSWORD} default

# this will be set in initial login test
${bearerToken} default
${userId} default

2 changes: 2 additions & 0 deletions robot/tests/01_loginTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ Verify user can login
${response}= POST ${URL}/auth/login json=${data} expected_status=200
Should Be True ${response.json()['ok']}
Set Global Variable ${bearerToken} access_token=${response.json()['secret']}
Set Global Variable ${userId} ${response.json()['userId']}
Log To Console ${bearerToken}
Log To Console ${userId}
10 changes: 0 additions & 10 deletions robot/tests/04_bookTests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ Verify that a nonexistent book can't be deleted
${response}= DELETE url=${URL}/book/?id=12321&${bearerToken} expected_status=403
Should Not Be True ${response.json()['ok']}

Verify user can check all borrowed books
${response}= GET url=${URL}/borrow/all?${bearerToken} expected_status=200

Verify that user cannot get a nonexisting borrowed book
${response}= GET url=${URL}/borrow/?id=123456789&${bearerToken} expected_status=200
Should Be Equal ${response.json()} ${None}

Verify that user can check borrowed book by id
${response}= GET url=${URL}/borrow/?id=1&${bearerToken} expected_status=200
Should Be Equal ${response.json()['id']} ${1}

# Verify that book can be updated
# &{data}= Create dictionary { library_user=2 title=Fake asdf image=http://books.google.com/books/content?id=ILqrxQEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api author=Test Author year=2022 isbn=123-242-421 topic=js location=Fake location deleted=0}
Expand Down
32 changes: 32 additions & 0 deletions robot/tests/05_borrowTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String

*** Test Cases ***
Verify that all borrows can be found
${response}= GET url=${URL}/borrow/all?${bearerToken} expected_status=200

Verify that user can find borrow by id
${response}= GET url=${URL}/borrow/?id=1&${bearerToken} expected_status=200
Should Be Equal ${response.json()['id']} ${1}

Verify that user can't find borrow by non-existing id
${response}= GET url=${URL}/borrow/?id=12345&${bearerToken} expected_status=200
Should Be Equal ${response.json()} ${none}

Verify that user can check borrowed book by id
${response}= GET url=${URL}/borrow/?id=1&${bearerToken} expected_status=200
Should Be Equal ${response.json()['id']} ${1}

Verify that user can't delete non-existing borrow
&{data}= Create dictionary
... { bookId=1234 }
${response}= DELETE url=${URL}/borrow?${bearerToken} json=${data} expected_status=403

Verify that user can get current borrows
${response}= GET url=${URL}/borrow/current?${bearerToken} expected_status=200

Verify that user can get borrows by session
${response}= GET url=${URL}/borrow/session?${bearerToken} expected_status=200

82 changes: 82 additions & 0 deletions robot/tests/06_booklistTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String

*** Variables ***
${okTrueJson} {"ok":true}
${okFalseJson} {"ok":false}

*** Test Cases ***
Verify that user can add booklists
${data}= Create dictionary
... name=Testlist
${response}= POST url=${URL}/booklist?${bearerToken} json=${data} expected_status=200

Verify that user can check all booklists
${response}= GET url=${URL}/booklist/all?${bearerToken} expected_status=200

Verify that user can check all users booklists
${response}= GET url=${URL}/booklist/user?${bearerToken} expected_status=200
${bookList}= Evaluate json.loads('''${response.text}''')
Length Should Be ${bookList} 1

Verify that user can add books to list
${data}= Create dictionary
... list=1
... book=2
${response}= POST url=${URL}/booklistentry?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't add non-existing books to list
${data}= Create dictionary
... list=1
... book=2123
${response}= POST url=${URL}/booklistentry?${bearerToken} json=${data} expected_status=500
Should Be Equal As Strings ${response.text} ${okFalseJson}

Verify that user can't add books to non-existing list
${data}= Create dictionary
... list=11234
... book=2
${response}= POST url=${URL}/booklistentry?${bearerToken} json=${data} expected_status=500
Should Be Equal As Strings ${response.text} ${okFalseJson}

Verify that user can get all booklistentrys
${response}= GET url=${URL}/booklistentry/all?${bearerToken} expected_status=200

Verify that user get all booklistentrys based on listId
${response}= GET url=${URL}/booklistentry/list?${bearerToken}&id=1 expected_status=200
${bookList}= Evaluate json.loads('''${response.text}''')
Length Should Be ${bookList} 1

Verify that user get all books in list based on listId
${response}= GET url=${URL}/booklist/books?${bearerToken}&id=1 expected_status=200
${bookList}= Evaluate json.loads('''${response.text}''')
Length Should Be ${bookList} 1

Verify that user can modify booklist
${data}= Create dictionary
... id=1
... name=New name
${response}= PUT url=${URL}/booklist?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't modify non-existing booklist
${data}= Create dictionary
... id=12345
... name=Wrong list
${response}= PUT url=${URL}/booklist?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okFalseJson}

Verify that user can delete booklist
${data}= Create dictionary
... id=1
${response}= DELETE url=${URL}/booklist?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't delete non-existing booklist
${data}= Create dictionary
... id=1123
${response}= DELETE url=${URL}/booklist?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okFalseJson}
34 changes: 34 additions & 0 deletions robot/tests/07_bookFavoriteTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String

*** Test Cases ***
Verify that user can add favorite
&{data}= Create dictionary
... bookId=4
${response}= POST url=${URL}/favorite?${bearerToken} json=${data} expected_status=200
Should Be True ${response.json()['ok']}

Verify that user can get counts for all favorited books
${response}= GET url=${URL}/favorite/counts?${bearerToken} expected_status=200

Verify that user can get count for books
${response}= GET url=${URL}/favorite/count?${bearerToken}&bookId=4 expected_status=200
Should Be Equal ${response.json()['count']} ${1}

Verify that user can check if book is favorited
${response}= GET url=${URL}/favorite/check?${bearerToken}&bookId=4 expected_status=200
Should Be Equal ${response.json()['isFavorited']} ${true}

Verify that user can delete book from favorites
&{data}= Create dictionary
... bookId=4
${response}= DELETE url=${URL}/favorite?${bearerToken} json=${data} expected_status=200
Should Be True ${response.json()['ok']}

Verify that user can't delete book that isn't favorited
&{data}= Create dictionary
... bookId=3123
${response}= DELETE url=${URL}/favorite?${bearerToken} expected_status=400
Should Not Be True ${response.json()['ok']}
48 changes: 48 additions & 0 deletions robot/tests/08_bookReviewTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String

*** Variables ***
${okTrueJson} {"ok":true}
${okFalseJson} {"ok":false}


*** Test Cases ***
Verify that user can add review to book
${data}= Create dictionary
... bookId=1
... comment='Great book for everyone!'
... rating=5
${response}= POST url=${URL}/review?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't add review to non-existing book
${data}= Create dictionary
... bookId=1124
... comment='Wrong book'
... rating=1
${response}= POST url=${URL}/review?${bearerToken} json=${data} expected_status=500
Should Be Equal As Strings ${response.text} ${okFalseJson}

Verify that user can check all reviews
${response}= GET url=${URL}/review/all?${bearerToken} expected_status=200

Verify that user can check reviews for all books
${response}= GET url=${URL}/review/reviews?${bearerToken} expected_status=200

Verify that user can modify review
${data}= Create dictionary
... comment='Modified book'
... rating=1
... reviewId=1
${response}= PUT url=${URL}/review?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't modify non-existing review
${data}= Create dictionary
... comment='Again wrong book'
... rating=1
... reviewId=1234
${response}= PUT url=${URL}/review?${bearerToken} json=${data} expected_status=400
Should Not Be True ${response.json()['ok']}
18 changes: 18 additions & 0 deletions robot/tests/09_bookRequestTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String


*** Test Cases ***
Verify that user can add request
${data}= Create dictionary
... isbn=234-123-345
... title=Lizard Disco
... reason=Great book, easy to read
${response}= POST url=${URL}/bookrequest?${bearerToken} json=${data} expected_status=200

Verify that user can check all users booklists
${response}= GET url=${URL}/bookrequest/all?${bearerToken} expected_status=200
${list}= Evaluate json.loads('''${response.text}''')
Length Should Be ${list} 1
67 changes: 67 additions & 0 deletions robot/tests/10_bookReservationTests.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
*** Settings ***
Resource ../common.resource
Library RequestsLibrary
Library String

*** Variables ***
${okTrueJson} {"ok":true}
${okFalseJson} {"ok":false}

*** Test Cases ***
Verify that user can add reservations
${data}= Create dictionary
... bookId=2
${response}= POST url=${URL}/bookreservation?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can't add reservations for non-existing book
${data}= Create dictionary
... bookId=1123
${response}= POST url=${URL}/bookreservation?${bearerToken} json=${data} expected_status=500
Should Be Equal As Strings ${response.text} ${okFalseJson}

Verify that user can check all reservations
${response}= GET url=${URL}/bookreservation/all?${bearerToken} expected_status=200
${list}= Evaluate json.loads('''${response.text}''')
Length Should Be ${list} 1

Verify that user can check all extended reservations
${response}= GET url=${URL}/bookreservation/all/extended?${bearerToken} expected_status=200
${list}= Evaluate json.loads('''${response.text}''')
Length Should Be ${list} 1

Verify that user can check reservation based on bookId
${data}= Create dictionary
... bookId=2
${response}= GET url=${URL}/bookreservation/book?${bearerToken} json=${data} expected_status=200
Should Be Equal ${response.json()['bookId']} ${2}

Verify that user can't check reservation based on non-existing bookId
${data}= Create dictionary
... bookId=33245
${response}= GET url=${URL}/bookreservation/book?${bearerToken} json=${data} expected_status=200
Should Be Equal ${response.json()} ${none}

Verify that user can cancel reservation
${data}= Create dictionary
... reservationId=1
${response}= POST url=${URL}/bookreservation/cancel?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can check all current reservations
${response}= GET url=${URL}/bookreservation/all/current?${bearerToken} expected_status=200
${list}= Evaluate json.loads('''${response.text}''')
Length Should Be ${list} 0

Verify that user can loan reservation
${data}= Create dictionary
... reservationId=1
${response}= POST url=${URL}/bookreservation/loan?${bearerToken} json=${data} expected_status=200
Should Be Equal As Strings ${response.text} ${okTrueJson}

Verify that user can see their current reservations
${data}= Create dictionary
... userId=${userId}
${response}= POST url=${URL}/bookreservation/user/current?${bearerToken} json=${data} expected_status=200
${list}= Evaluate json.loads('''${response.text}''')
Should Be Equal ${response.json()} ${none}
File renamed without changes.
Loading