From afc92d38c895b3949e24485d50576524eb2e2b1e Mon Sep 17 00:00:00 2001 From: ptruneac Date: Fri, 20 Sep 2024 15:59:54 +0300 Subject: [PATCH] E2e test finished --- api/end-to-end_tests/test_borrowed_books.yaml | 76 +++++++++++++++++++ api/end-to-end_tests/test_users.yaml | 63 +++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 api/end-to-end_tests/test_borrowed_books.yaml create mode 100644 api/end-to-end_tests/test_users.yaml diff --git a/api/end-to-end_tests/test_borrowed_books.yaml b/api/end-to-end_tests/test_borrowed_books.yaml new file mode 100644 index 0000000..2377465 --- /dev/null +++ b/api/end-to-end_tests/test_borrowed_books.yaml @@ -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" diff --git a/api/end-to-end_tests/test_users.yaml b/api/end-to-end_tests/test_users.yaml new file mode 100644 index 0000000..c52699b --- /dev/null +++ b/api/end-to-end_tests/test_users.yaml @@ -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": "testuser@gmail.com", + "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": "testuser@gmail.com", + "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": "testuser@gmail.com", + "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": "testuser@gmail.com", + "password": "anotherpassword" + } + assertions: + - result.statuscode ShouldEqual 409 + - result.bodyjson.message ShouldEqual "Email already in use" \ No newline at end of file