Skip to content

Commit

Permalink
E2e test finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip-Petruneac committed Sep 20, 2024
1 parent 319027c commit afc92d3
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
76 changes: 76 additions & 0 deletions api/end-to-end_tests/test_borrowed_books.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
version: "2"
name: Test Borrow and Return Book Handlers

vars:
api.url: "http://localhost:8081"

steps:
# Step 1: Test BorrowBook with valid data
- name: Borrow a book with valid data
type: http
method: POST
url: "{{ api.url }}/borrow-book"
body: |
{
"subscriber_id": 1,
"book_id": 1
}
assertions:
- result.statuscode ShouldEqual 201
- result.bodyjson.message ShouldEqual "Book borrowed successfully"

# Step 2: Test BorrowBook with already borrowed book
- name: Try to borrow an already borrowed book
type: http
method: POST
url: "{{ api.url }}/borrow-book"
body: |
{
"subscriber_id": 1,
"book_id": 1
}
assertions:
- result.statuscode ShouldEqual 409
- result.body ShouldContain "Book is already borrowed"

# Step 3: Test BorrowBook with missing fields
- name: BorrowBook with missing fields
type: http
method: POST
url: "{{ api.url }}/borrow-book"
body: |
{
"subscriber_id": 0,
"book_id": 1
}
assertions:
- result.statuscode ShouldEqual 400
- result.body ShouldContain "Missing required fields"

# Step 4: Test ReturnBorrowedBook with valid data
- name: Return a borrowed book
type: http
method: POST
url: "{{ api.url }}/return-borrowed-book"
body: |
{
"subscriber_id": 1,
"book_id": 1
}
assertions:
- result.statuscode ShouldEqual 200
- result.body ShouldContain "Book returned successfully"

# Step 5: Test ReturnBorrowedBook for a book not borrowed
- name: Try to return a book that was not borrowed
type: http
method: POST
url: "{{ api.url }}/return-borrowed-book"
body: |
{
"subscriber_id": 1,
"book_id": 2
}
assertions:
- result.statuscode ShouldEqual 400
- result.body ShouldContain "Book is not borrowed"
63 changes: 63 additions & 0 deletions api/end-to-end_tests/test_users.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: User signup and login tests

vars:
api.url: "http://localhost:8081"
mysql.url: "filip:password@(localhost:4450)/db"

steps:
# Step 1: Test Signup with valid data
- name: Signup with valid data
type: http
method: POST
url: "{{ api.url }}/signup"
body: |
{
"email": "[email protected]",
"password": "password123"
}
assertions:
- result.statuscode ShouldEqual 201
- result.bodyjson.message ShouldEqual "User registered successfully"

# Step 2: Test Login with valid credentials
- name: Login with valid credentials
type: http
method: POST
url: "{{ api.url }}/login"
body: |
{
"email": "[email protected]",
"password": "password123"
}
assertions:
- result.statuscode ShouldEqual 200
- result.bodyjson.message ShouldEqual "User logged in successfully"
- result.bodyjson.existingUserID ShouldNotBeEmpty

# Step 3: Test Login with invalid credentials
- name: Login with invalid credentials
type: http
method: POST
url: "{{ api.url }}/login"
body: |
{
"email": "[email protected]",
"password": "wrongpassword"
}
assertions:
- result.statuscode ShouldEqual 400
- result.bodyjson.message ShouldEqual "Invalid email or password"

# Step 4: Test Signup with an already registered email
- name: Signup with existing email
type: http
method: POST
url: "{{ api.url }}/signup"
body: |
{
"email": "[email protected]",
"password": "anotherpassword"
}
assertions:
- result.statuscode ShouldEqual 409
- result.bodyjson.message ShouldEqual "Email already in use"

0 comments on commit afc92d3

Please sign in to comment.