Skip to content

Commit db5d40d

Browse files
committed
Fixing the data helpers
1 parent 4c84361 commit db5d40d

File tree

8 files changed

+80
-45
lines changed

8 files changed

+80
-45
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
submodules: false
4949

5050
- name: Build and start Docker Compose services
51-
run: bash ./setup_github.sh && docker compose up --build -d
51+
run: bash ./build_github.sh
5252

5353
- name: check dns is working
5454
run: cat /etc/hosts; netstat -tulpn # Use -tulpn to show TCP/UDP listeners
@@ -65,9 +65,9 @@ jobs:
6565
config: pageLoadTimeout=100000,baseUrl=http://localhost:8089
6666
working-directory: test/
6767

68-
- name: Check if tests failed
69-
if: ${{ failure() }}
70-
uses: mxschmitt/action-tmate@v3
68+
# - name: Check if tests failed
69+
# if: ${{ failure() }}
70+
# uses: mxschmitt/action-tmate@v3
7171

7272
- name: Save artifact
7373
uses: actions/upload-artifact@v4

build_github.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
source ./setup_github.sh
2+
source .env
33

44
# Run Docker Compose without local volumes
5-
docker-compose -f docker-compose.yaml up --build --no-deps
5+
docker-compose up --build --no-deps -d

build_local.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
2-
32
source ./setup_local.sh
43

54
# Run Docker Compose
6-
docker-compose up --build
5+
docker-compose up --build -d

repo_refs/rails-app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit a99a8fe5362a1541a58059e0c03ae3a5fd392802
1+
Subproject commit 6479f9e9a4a8041809a3b3f1ef1ac8359c8f665b

setup_github.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/cypress/e2e/books_flow.cy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe("Books Flow", () => {
1212
// Propose a new book
1313
cy.contains("button", "Propose New Book").click();
1414
cy.get('input[placeholder="Enter book title"]').type("Test Book Title");
15+
cy.get('input[placeholder="Enter book publisher"]').type(
16+
"Test Author Name"
17+
);
18+
cy.get('input[placeholder="Enter book author"]').type(
19+
"Test Publisher Name"
20+
);
1521
cy.contains("button", "Submit").click();
1622

1723
// Visit React2 app (/backend path)
@@ -43,6 +49,12 @@ describe("Books Flow", () => {
4349
// Propose a new book
4450
cy.contains("button", "Propose New Book").click();
4551
cy.get('input[placeholder="Enter book title"]').type("Book To Deny");
52+
cy.get('input[placeholder="Enter book publisher"]').type(
53+
"Test Author Name"
54+
);
55+
cy.get('input[placeholder="Enter book author"]').type(
56+
"Test Publisher Name"
57+
);
4658
cy.contains("button", "Submit").click();
4759

4860
// Visit React2 app and deny the book

test/cypress/e2e/data_helpers.cy.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
// This test suite is designed to verify the functionality of Cypress data helpers.
22
// It should be run before other test suites to ensure data helpers are working correctly.
33

4-
describe("Cypress Data Helpers", () => {
5-
it("should verify the data helper for creating test data", () => {
6-
cy.request("POST", "/api/test_data/setup", {
7-
/* payload */
8-
}).then((response) => {
9-
expect(response.status).to.eq(200);
10-
// Add more assertions based on the expected response
11-
});
4+
describe("Cypress Data Helpers", async () => {
5+
beforeEach(() => {
6+
cy.resetTestData();
127
});
138

14-
it("should verify the data helper for resetting test data", () => {
15-
cy.request("POST", "/api/test_data/reset").then((response) => {
16-
expect(response.status).to.eq(200);
17-
// Add more assertions based on the expected response
9+
it("should verify the data helper for creating test data", async () => {
10+
cy.setupApprovedBook("Book1", "Author1", "Publisher1");
11+
cy.setupApprovedBook("Book2", "Author2", "Publisher2");
12+
cy.setupApprovedBook("Book3", "Author3", "Publisher3");
13+
14+
// Perform a GET request to verify data creation
15+
cy.request("GET", "/api/books").then((getResponse) => {
16+
expect(getResponse.status).to.eq(200);
17+
expect(getResponse.body).to.have.lengthOf(3);
1818
});
1919
});
2020

21-
// Add more tests for other data helpers as needed
21+
it("should verify the data helper for resetting test data", async () => {
22+
// Create books first
23+
cy.setupApprovedBook("Book1", "Author1", "Publisher1");
24+
cy.setupApprovedBook("Book2", "Author2", "Publisher2");
25+
cy.setupApprovedBook("Book3", "Author3", "Publisher3");
26+
27+
// Verify books are created
28+
cy.request("GET", "/api/books").then(async (getResponse) => {
29+
expect(getResponse.status).to.eq(200);
30+
expect(getResponse.body).to.have.lengthOf(3);
31+
32+
// Reset the database
33+
cy.request("POST", "/api/test_data/reset").then((resetResponse) => {
34+
expect(resetResponse.status).to.eq(200);
35+
36+
// Verify books are removed
37+
cy.request("GET", "/api/books").then((finalGetResponse) => {
38+
expect(finalGetResponse.status).to.eq(200);
39+
expect(finalGetResponse.body).to.have.lengthOf(0);
40+
});
41+
});
42+
});
43+
});
2244
});

test/cypress/support/test_data.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,35 @@ Cypress.Commands.add("setupProvisionalBook", (title = "Test Book") => {
3838
]);
3939
});
4040

41-
Cypress.Commands.add("setupApprovedBook", (title = "Approved Book") => {
42-
cy.createTestData([
43-
{
44-
factory: "book",
45-
attributes: {
46-
title,
47-
status: "approved",
41+
Cypress.Commands.add(
42+
"setupApprovedBook",
43+
(
44+
title = "Approved Book",
45+
author_name = "Test Author",
46+
publisher_name = "Test Publisher"
47+
) => {
48+
cy.createTestData([
49+
{
50+
factory: "book",
51+
attributes: {
52+
title,
53+
author_attributes: {
54+
name: author_name,
55+
},
56+
publisher_attributes: {
57+
name: publisher_name,
58+
},
59+
status: "approved",
60+
},
4861
},
49-
},
50-
]);
51-
});
62+
]);
63+
}
64+
);
5265

5366
Cypress.Commands.add(
5467
"setupBookWithAuthorAndPublisher",
5568
({
56-
bookTitle = "Test Book",
69+
title = "Test Book",
5770
authorName = "Test Author",
5871
publisherName = "Test Publisher",
5972
status = "approved",
@@ -62,7 +75,7 @@ Cypress.Commands.add(
6275
{
6376
factory: "book",
6477
attributes: {
65-
title: bookTitle,
78+
title,
6679
status,
6780
author_attributes: {
6881
name: authorName,

0 commit comments

Comments
 (0)