Skip to content

Commit c754dfa

Browse files
committed
cyrpress wip not working yet
1 parent 4dd7885 commit c754dfa

15 files changed

+2258
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131
.vscode/
132+
.DS_Store

compose.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ services:
1919
- DATABASE_HOST=${DATABASE_HOST}
2020
- DATABASE_USERNAME=${DATABASE_USERNAME}
2121
- RAILS_ENV=${RAILS_ENV}
22+
- BIND=tcp://0.0.0.0:3000
23+
healthcheck:
24+
test: ["CMD", "curl", "-f", "http://localhost:3000/api/ping"]
25+
interval: 10s
26+
timeout: 5s
27+
retries: 3
2228
depends_on:
2329
db:
2430
condition: service_healthy
@@ -61,6 +67,20 @@ services:
6167
networks:
6268
- app-network
6369

70+
test:
71+
build: ./test
72+
networks:
73+
- app-network
74+
volumes:
75+
- ./test:/app
76+
environment:
77+
- CYPRESS_BASE_URL=http://nginx:80
78+
depends_on:
79+
- nginx
80+
- api
81+
- frontend
82+
- backend
83+
6484
networks:
6585
app-network:
6686
driver: bridge

nginx/default.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ server {
1919
proxy_http_version 1.1; # Required for WebSocket
2020
proxy_buffering off; # Disable buffering for real-time communication
2121

22-
2322
proxy_pass http://frontend:3000;
2423
proxy_redirect off;
2524
}

repo_refs/rails-app

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 1ad36c4eb184bd9fd9e6142a1d482b2e2ed99047
1+
Subproject commit f488bd28da264631b4c7d38818f0c1d5bad7f20e

test/Dockerfile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
FROM cypress/included:13.6.1
1+
FROM node:18
2+
3+
# Install Cypress dependencies
4+
RUN apt-get update && apt-get install -y \
5+
libgtk2.0-0 \
6+
libgtk-3-0 \
7+
libgbm-dev \
8+
libnotify-dev \
9+
libgconf-2-4 \
10+
libnss3 \
11+
libxss1 \
12+
libasound2 \
13+
libxtst6 \
14+
xauth \
15+
xvfb \
16+
&& rm -rf /var/lib/apt/lists/*
217

318
WORKDIR /app
419

520
# Copy package files
621
COPY package*.json ./
22+
23+
# Install dependencies
724
RUN npm install
825

9-
# Copy Cypress files
10-
COPY cypress.config.js .
11-
COPY cypress/ ./cypress/
26+
# Copy the rest of the application
27+
COPY . .
1228

13-
CMD ["cypress", "run"]
29+
# Keep container running for development
30+
CMD ["tail", "-f", "/dev/null"]

test/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Cypress Tests
2+
3+
This directory contains end-to-end tests using Cypress for the Books application.
4+
5+
## Setup
6+
7+
The tests can be run either locally or through Docker, depending on your preference during development.
8+
9+
### Local Development
10+
11+
1. Install dependencies:
12+
13+
```bash
14+
npm install
15+
```
16+
17+
2. Make sure the application is running (docker compose up):
18+
19+
- Frontend at http://localhost:8089
20+
- Backend at http://localhost:8089/backend
21+
- API at http://localhost:8089/api
22+
23+
3. Run tests:
24+
25+
```bash
26+
# Open Cypress GUI for development
27+
npm run test:local
28+
29+
# Run tests headlessly
30+
npm test
31+
```
32+
33+
### Docker Environment
34+
35+
The tests can also be run through Docker, which is how they'll run in CI/CD:
36+
37+
```bash
38+
# Run tests headlessly in Docker
39+
npm run test:docker
40+
41+
# Open Cypress GUI in Docker
42+
npm run test:docker:open
43+
```
44+
45+
## Test Data Helpers
46+
47+
The `cypress/support/test_data.js` file provides helper commands for managing test data:
48+
49+
- `cy.resetTestData()` - Clears all test data
50+
- `cy.createTestData(data)` - Creates test data using factory_bot factories
51+
- `cy.setupProvisionalBook(title)` - Creates a book with provisional status
52+
- `cy.setupApprovedBook(title)` - Creates a book with approved status
53+
- `cy.setupBookWithAuthorAndPublisher(options)` - Creates a book with associated author and publisher
54+
55+
Example usage:
56+
57+
```javascript
58+
beforeEach(() => {
59+
cy.resetTestData();
60+
});
61+
62+
it("displays approved books", () => {
63+
cy.setupApprovedBook("Test Book");
64+
cy.visit("/");
65+
cy.contains("Test Book");
66+
});
67+
```
68+
69+
## Configuration
70+
71+
The tests are configured to work in both local and Docker environments:
72+
73+
- Local development uses http://localhost:8089
74+
- Docker environment uses http://nginx:80
75+
- The base URL can be overridden with the CYPRESS_BASE_URL environment variable
76+
77+
See `cypress.config.js` for more configuration options.

test/cypress.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { defineConfig } = require("cypress");
22

33
module.exports = defineConfig({
44
e2e: {
5-
baseUrl: "http://localhost:3050",
5+
baseUrl: process.env.CYPRESS_BASE_URL || "http://localhost:8089",
66
setupNodeEvents(on, config) {
77
// implement node event listeners here
88
},

test/cypress/e2e/books_flow.cy.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe("Books Flow", () => {
22
beforeEach(() => {
33
// Reset database before each test
4-
cy.request("POST", "/api/test_data/reset");
4+
cy.resetTestData();
55
});
66

77
it("allows proposing and approving books", () => {
@@ -56,8 +56,10 @@ describe("Books Flow", () => {
5656
});
5757

5858
it("displays test data books", () => {
59-
// Load test data
60-
cy.request("POST", "/api/test_data/load");
59+
// Setup test books
60+
cy.setupApprovedBook("Test Book 1");
61+
cy.setupApprovedBook("Test Book 2");
62+
cy.setupApprovedBook("Test Book 3");
6163

6264
// Visit React1 app
6365
cy.visit("/");
@@ -67,4 +69,22 @@ describe("Books Flow", () => {
6769
cy.contains("Test Book 2");
6870
cy.contains("Test Book 3");
6971
});
72+
73+
it("displays books with authors and publishers", () => {
74+
// Setup a book with author and publisher
75+
cy.setupBookWithAuthorAndPublisher({
76+
bookTitle: "Complete Guide to Testing",
77+
authorName: "Jane Tester",
78+
publisherName: "Test Publishing House",
79+
status: "approved",
80+
});
81+
82+
// Visit React1 app
83+
cy.visit("/");
84+
85+
// Verify book details
86+
cy.contains("Complete Guide to Testing");
87+
cy.contains("Jane Tester");
88+
cy.contains("Test Publishing House");
89+
});
7090
});

test/cypress/e2e/connectivity.cy.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
describe("Service Connectivity", () => {
2+
it("can access frontend", () => {
3+
cy.visit("/");
4+
cy.contains("Book List").should("exist");
5+
});
6+
7+
it("can access backend", () => {
8+
cy.visit("/backend/");
9+
cy.contains("Provisional Books").should("exist");
10+
});
11+
12+
it("can access API", () => {
13+
// Add retry logic for API readiness
14+
cy.request({
15+
url: "/api/test_data/factories",
16+
retryOnStatusCodeFailure: true,
17+
timeout: 30000,
18+
}).then((response) => {
19+
expect(response.status).to.eq(200);
20+
expect(response.body).to.have.property("factories");
21+
});
22+
});
23+
24+
it("can use test data helpers", () => {
25+
// Wait for API to be ready before using test data helpers
26+
cy.request({
27+
url: "/api/test_data/factories",
28+
retryOnStatusCodeFailure: true,
29+
timeout: 30000,
30+
}).then(() => {
31+
// Reset test data
32+
cy.resetTestData();
33+
34+
// Create a test book
35+
cy.setupApprovedBook("Connectivity Test Book");
36+
37+
// Verify the book appears
38+
cy.visit("/");
39+
cy.contains("Connectivity Test Book", { timeout: 10000 }).should("exist");
40+
});
41+
});
42+
});
113 KB
Loading

0 commit comments

Comments
 (0)