Skip to content

Commit c8f437c

Browse files
authored
Merge branch 'staging' into ben/n4-attempt
2 parents 87d1299 + 513fc88 commit c8f437c

File tree

9 files changed

+292
-36
lines changed

9 files changed

+292
-36
lines changed

.github/workflows/test.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v2
22-
22+
2323
- name: Set up .env
2424
env:
2525
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
@@ -30,7 +30,7 @@ jobs:
3030
echo "FIREBASE_CREDENTIAL_PATH=$QUESTION_FIREBASE_CREDENTIAL_PATH" >> .env
3131
echo "JWT_SECRET=$JWT_SECRET" >> .env
3232
echo "EXECUTION_SERVICE_URL=$EXECUTION_SERVICE_URL" >> .env
33-
33+
3434
- name: Set up credentials
3535
env:
3636
QUESTION_FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
@@ -41,8 +41,8 @@ jobs:
4141
4242
- name: Setup Go
4343
uses: actions/setup-go@v5
44-
with:
45-
go-version: "1.23.x"
44+
with:
45+
go-version: '1.23.x'
4646

4747
- name: Install Go dependencies
4848
run: |
@@ -51,7 +51,7 @@ jobs:
5151
5252
- name: Install firebase tools
5353
run: curl -sL firebase.tools | bash
54-
54+
5555
- name: Run Go tests with Firebase emulator
5656
run: firebase emulators:exec --only firestore 'cd ./apps/question-service; go test -v ./tests'
5757

@@ -66,11 +66,11 @@ jobs:
6666
run: |
6767
cd ./apps/frontend
6868
cp .env.example .env
69-
69+
7070
- name: Set up Node.js
7171
uses: actions/setup-node@v2
7272
with:
73-
node-version: "22"
73+
node-version: '22'
7474

7575
- name: Install pnpm
7676
run: npm i -g pnpm
@@ -83,7 +83,7 @@ jobs:
8383
- name: Run tests
8484
run: |
8585
cd ./apps/frontend
86-
pnpm test
86+
pnpm unit-test
8787
8888
test-docker-compose:
8989
runs-on: ubuntu-latest
@@ -117,7 +117,6 @@ jobs:
117117
EXECUTION_SERVICE_PORT: ${{ vars.EXECUTION_SERVICE_PORT }}
118118
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
119119
REDIS_URL: ${{ vars.REDIS_URL }}
120-
RABBITMQ_URL: ${{ vars.RABBITMQ_URL }}
121120
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
122121
run: |
123122
cd ./apps/frontend
@@ -148,13 +147,11 @@ jobs:
148147
cd ../history-service
149148
echo "FIREBASE_CREDENTIAL_PATH=$HISTORY_FIREBASE_CREDENTIAL_PATH" >> .env
150149
echo "PORT=$HISTORY_SERVICE_PORT" >> .env
151-
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
152-
150+
153151
cd ../execution-service
154152
echo "FIREBASE_CREDENTIAL_PATH=$EXECUTION_FIREBASE_CREDENTIAL_PATH" >> .env
155153
echo "PORT=$EXECUTION_SERVICE_PORT" >> .env
156154
echo "HISTORY_SERVICE_URL=$HISTORY_SERVICE_URL" >> .env
157-
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
158155
159156
cd ../signalling-service
160157
echo "PORT=$SIGNALLING_SERVICE_PORT" >> .env
@@ -173,7 +170,7 @@ jobs:
173170
174171
cd ../history-service
175172
echo "$HISTORY_FIREBASE_JSON" > "./$HISTORY_FIREBASE_CREDENTIAL_PATH"
176-
173+
177174
cd ../execution-service
178175
echo "$EXECUTION_FIREBASE_JSON" > "./$EXECUTION_FIREBASE_CREDENTIAL_PATH"
179176
@@ -225,3 +222,30 @@ jobs:
225222
echo "WebSocket for Signalling Service is live"
226223
fi
227224
# We can add more tests here
225+
226+
- name: Install pnpm
227+
uses: pnpm/action-setup@v4
228+
with:
229+
version: 9.1.4
230+
231+
- name: Install dependencies
232+
run: |
233+
cd ./apps/frontend
234+
pnpm i
235+
236+
- name: Install Chrome WebDriver
237+
uses: nanasess/setup-chromedriver@v2
238+
with:
239+
chromedriver-version: '130.0.6723.116'
240+
- name: Install Edge
241+
uses: browser-actions/setup-edge@v1
242+
with:
243+
edge-version: stable
244+
245+
- name: Install Geckodriver
246+
uses: browser-actions/setup-geckodriver@latest
247+
248+
- name: Run Browser Test
249+
run: |
250+
cd ./apps/frontend
251+
pnpm browser-test
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Actions, Browser, Builder, By, Capabilities, Key, until, WebDriver } from "selenium-webdriver"
2+
3+
import {Options as ChromeOptions} from "selenium-webdriver/chrome"
4+
import {Options as EdgeOptions} from "selenium-webdriver/edge"
5+
import {Options as FirefoxOptions} from "selenium-webdriver/firefox"
6+
7+
const URL = 'http://localhost:3000/';
8+
const ETERNAL_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTk5fQ.Z4_FVGQ5lIcouP3m4YLMr6pGMF17IJFfo2yOTiN58DY"
9+
10+
const CHROME_OPTIONS = new ChromeOptions()
11+
.addArguments("--headless=new") as ChromeOptions; // uncomment locally to see the steps in action
12+
const EDGE_OPTIONS = new EdgeOptions()
13+
.setBinaryPath("/opt/hostedtoolcache/msedge/stable/x64/msedge") // need to point to the correct path
14+
.addArguments("--headless=new") as EdgeOptions;
15+
16+
const FIREFOX_OPTIONS = new FirefoxOptions()
17+
.addArguments("--headless") as FirefoxOptions;
18+
19+
const builder = new Builder()
20+
.setChromeOptions(CHROME_OPTIONS)
21+
.setEdgeOptions(EDGE_OPTIONS)
22+
.setFirefoxOptions(FIREFOX_OPTIONS)
23+
24+
describe.each([Browser.CHROME, Browser.EDGE, Browser.FIREFOX])("%s driver test", (browser) => {
25+
let driver: WebDriver;
26+
beforeAll(() => {
27+
const cap = new Capabilities().setBrowserName(browser)
28+
builder.withCapabilities(cap);
29+
})
30+
31+
beforeEach(async () => {
32+
console.log(browser + ": building...");
33+
driver = await builder.build();
34+
console.log(browser + ": built");
35+
}, 20000)
36+
37+
afterEach(async () => {
38+
if (driver) {
39+
await driver.quit();
40+
}
41+
})
42+
43+
describe("webdriver installed correctly", () => {
44+
it("does google search", async () => {
45+
await driver.get('http://www.google.com');
46+
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
47+
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
48+
}, 10000);
49+
50+
it.skip("does another google search", async () => {
51+
await driver.get('http://www.google.com');
52+
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
53+
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
54+
}, 10000);
55+
});
56+
57+
describe("browser-test", () => {
58+
it("accesses and login to peerprep", async () => {
59+
await driver.get(URL);
60+
await driver.wait(until.urlIs(`${URL}login`));
61+
62+
const [email, password] = await driver.findElements(By.css("input"))
63+
const submit = await driver.findElement(By.css("button[type=\"submit\"]"))
64+
65+
await email.sendKeys("[email protected]");
66+
await password.sendKeys("admin");
67+
68+
await submit.click();
69+
await driver.wait(until.urlIs(`${URL}`));
70+
71+
const slogan1 = await driver.findElement(By.xpath("/html/body/div[1]/main/div/div[1]/div[2]/span[1]")).then(ele => ele.getText())
72+
const slogan2 = await driver.findElement(By.xpath("/html/body/div[1]/main/div/div[1]/div[2]/span[2]")).then(ele => ele.getText())
73+
74+
expect(slogan1).toBe("A better way to prepare for coding interviews with");
75+
expect(slogan2).toBe("peers");
76+
}, 10000);
77+
})
78+
}, 60000)
79+
80+
81+
82+
File renamed without changes.
File renamed without changes.

apps/frontend/__tests__/question.test.ts renamed to apps/frontend/__tests__/unit-tests/question.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe("GetQuestions", () => {
126126

127127
});
128128

129-
it("gets all questions on the 2nd page with (2) call", async () => {
129+
it("formats (page=2) params correctly", async () => {
130130

131131
const res = await GetQuestions(2)
132132

@@ -138,7 +138,7 @@ describe("GetQuestions", () => {
138138
}]])
139139
});
140140

141-
it("gets all questions on the 2nd page with (limit=3) call", async () => {
141+
it("formats (limit=3) params correctly", async () => {
142142

143143
await GetQuestions(undefined, 3)
144144

@@ -150,7 +150,7 @@ describe("GetQuestions", () => {
150150
}]])
151151
});
152152

153-
it("gets all questions on the 2nd page with (limit=3) call", async () => {
153+
it("formats (difficulty asc) params correctly", async () => {
154154

155155
await GetQuestions(undefined, undefined, "difficulty asc")
156156

@@ -162,7 +162,7 @@ describe("GetQuestions", () => {
162162
}]])
163163
});
164164

165-
it("gets all questions on the 2nd page with (limit=3) call", async () => {
165+
it("formats ([\"easy\", \"hard\"]) params correctly", async () => {
166166

167167
await GetQuestions(undefined, undefined, undefined, ["easy", "hard"])
168168

@@ -174,7 +174,7 @@ describe("GetQuestions", () => {
174174
}]])
175175
});
176176

177-
it("formats urls for categories", async () => {
177+
it("formats cat params correctly", async () => {
178178

179179
await GetQuestions(undefined, undefined, undefined, undefined, ["CatA", "CatB"])
180180

@@ -189,7 +189,7 @@ describe("GetQuestions", () => {
189189
]])
190190
});
191191

192-
it("formats url for title", async () => {
192+
it("formats title params correctly", async () => {
193193

194194
await GetQuestions(undefined, undefined, undefined, undefined, undefined, "The Title Name")
195195

apps/frontend/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"test": "jest"
10+
"test": "jest",
11+
"unit-test": "jest --verbose __tests__/unit-tests",
12+
"browser-test": "jest --verbose __tests__/browser-tests"
1113
},
1214
"dependencies": {
1315
"@ant-design/icons": "^5.5.1",
@@ -40,16 +42,19 @@
4042
"@testing-library/dom": "^10.4.0",
4143
"@testing-library/jest-dom": "^6.6.3",
4244
"@testing-library/react": "^16.0.1",
45+
"@types/chromedriver": "^81.0.5",
4346
"@types/codemirror": "^5.60.15",
4447
"@types/jest": "^29.5.14",
4548
"@types/node": "^20",
4649
"@types/peerjs": "^1.1.0",
4750
"@types/react": "^18.3.8",
4851
"@types/react-dom": "^18.3.0",
52+
"@types/selenium-webdriver": "^4.1.27",
4953
"eslint": "^8",
5054
"eslint-config-next": "14.2.13",
5155
"jest": "^29.7.0",
5256
"jest-environment-jsdom": "^29.7.0",
57+
"selenium-webdriver": "^4.26.0",
5358
"ts-node": "^10.9.2",
5459
"typescript": "^5"
5560
},

0 commit comments

Comments
 (0)