Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smoke: introduce automated smoke tests #280

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: smoke

on:
push:
schedule:
# every 6 hours
- cron: 0 */6 * * *

jobs:
smoke:
name: smoke
runs-on: ubuntu-latest
steps:
- name: test-slack
- name: checkout
uses: actions/checkout@v3
- name: install pnpm
uses: pnpm/action-setup@v2
- name: get pnpm store path
id: pnpm-cache
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: |
${{ steps.pnpm-cache.outputs.STORE_PATH }}
~/.cache/Cypress
key: pnpm-cache-v1-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: pnpm-cache-v1-
- name: install deps
run: pnpm --filter @gertie/smoke-tests install
- name: setup just
uses: extractions/setup-just@v1
- name: run smoke tests
run: just smoke-run
- name: upload-videos
uses: actions/upload-artifact@v3
if: failure()
with:
name: smoke-videos
path: smoke/cypress/videos
- name: slack notify failure
if: failure()
run: |
curl -X POST \
-H "Content-type: application/json; charset=utf-8" \
-H "Authorization: Bearer $SLACK_API_TOKEN" \
-d "{\"channel\":\"G6007H2NM\",\"text\":\"Gertrude smoke test *FAILED*\", \
\"username\":\"Gertrude Bot\",\"icon_emoji\":\":fire_engine:\"}" \
https://slack.com/api/chat.postMessage

env:
CYPRESS_BASE_URL: https://parents.gertrude.app
CYPRESS_SMOKE_TEST_API_URL: https://api.gertrude.app
CYPRESS_SMOKE_TEST_EMAIL_INBOX_URL: ${{ secrets.SMOKE_TEST_EMAIL_INBOX_URL }}
SLACK_API_TOKEN: ${{ secrets.SLACK_API_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ appviews/src/main.tsx
storybook/storybook-static/
dash/app/build
dash/app/cypress/screenshots
smoke/cypress.env.json
**/cypress/downloads
**/cypress/videos
**/.next
Expand Down
5 changes: 4 additions & 1 deletion dash/components/src/Users/ConnectDeviceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const ConnectModal: React.FC<Props> = ({ dismissAddDevice, request }) => (
<div>
Enter the code below into the <i>Gertrude Mac App</i>:
</div>
<code className="block text-3xl text-fuchsia-700 tracking-widest font-bold bg-fuchsia-50 w-fit self-center px-4 py-1 rounded-lg">
<code
data-test="connection-code"
className="block text-3xl text-fuchsia-700 tracking-widest font-bold bg-fuchsia-50 w-fit self-center px-4 py-1 rounded-lg"
>
{payload.code}
</code>
<div>
Expand Down
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ cy-open:
cy-run:
@pnpm cypress run --project dash/app

smoke-open:
@pnpm cypress open --project smoke

smoke-run:
@pnpm cypress run --project smoke

test:
@pnpm vitest run

Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ packages:
- 'site/*'
- 'shared/*'
- 'storybook'
- 'smoke'
7 changes: 7 additions & 0 deletions smoke/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: { baseUrl: `http://localhost:8081` },
video: true,
viewportHeight: 800,
});
80 changes: 80 additions & 0 deletions smoke/cypress/e2e/smoke.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// <reference types="cypress" />
describe(`Smoke test`, () => {
const email = `82uii.smoke-test-${Date.now()}@inbox.testmail.app`;
const password = `_pw_${Date.now()}`;

it(`critical flows`, () => {
// signup
cy.visit(`/signup`);
cy.get(`input[name=email]`).type(email);
cy.get(`input[name=password]`).type(`${password}{enter}`);
cy.contains(`Verification email sent`);
cy.wait(Cypress.env(`CI`) ? 10000 : 2500);

// verify email
cy.request({ url: Cypress.env(`SMOKE_TEST_EMAIL_INBOX_URL`) }).then((response) => {
const body: string = response.body;
if (!body.includes(email)) {
throw new Error(`Expected to find email ${email} in ${body}`);
}
const match = body.match(/"([^" ]+verify-signup-email[^" ]+)"/);
if (!match) {
throw new Error(`Expected to find verify link in ${body}`);
}
cy.wrap(match[1]).as(`verifyLink`);
});
cy.get(`@verifyLink`).then((verifyLink) => {
cy.visit({ url: verifyLink as any });
});
cy.contains(`Welcome to the parent website!`);

// log out, then back in w/ email/pass
cy.contains(`Log out`).click();
cy.visit(`/`);
cy.location(`pathname`).should(`eq`, `/login`);
cy.get(`input[name=email]`).type(email);
cy.get(`input[name=password]`).type(`${password}{enter}`);
cy.location(`pathname`).should(`eq`, `/`);

// create a child
cy.contains(`Add a child`).click();
cy.get(`[data-test=user-name]`).type(`Franny`);
cy.contains(`Save child`).click();

// get the connection code
cy.contains(`Get connection code`).click();
cy.get(`[data-test=connection-code]`).invoke(`text`).as(`connectionCode`);

// simulate that they installed the app and connected successfully
cy.get(`@connectionCode`).then((connectionCode) => {
cy.log(`connectionCode`, connectionCode);
cy.request({
method: `POST`,
url: `${Cypress.env(`SMOKE_TEST_API_URL`)}/pairql/macos-app/ConnectUser`,
headers: { 'Content-Type': `application/json` },
body: {
verificationCode: Number(connectionCode),
appVersion: `2.1.2`,
modelIdentifier: `MacBookPro16,1`,
username: `franny`,
fullUsername: `Franny`,
numericId: 502,
serialNumber: `C02ZL0J${Math.random()}`,
},
})
.its(`status`)
.should(`eq`, 200);
});

// dismiss connection modal
cy.get(`[data-test="modal-primary-btn"]`).click();
cy.visit(`/children`);
cy.contains(`MacBook Pro`);

// edit the user
cy.contains(`Edit`).click();
cy.get(`[data-test=user-name]`).clear().type(`Franny (edited)`);
cy.contains(`Save child`).click();
cy.contains(`Child saved`);
});
});
1 change: 1 addition & 0 deletions smoke/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="cypress" />
1 change: 1 addition & 0 deletions smoke/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands';
9 changes: 9 additions & 0 deletions smoke/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@gertie/smoke-tests",
"version": "1.0.0",
"main": "src/index.ts",
"license": "ISC",
"devDependencies": {
"cypress": "13.6.1"
}
}
10 changes: 10 additions & 0 deletions smoke/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Gertie Smoke Tests

For local testing, add a `./smoke/cypress.env.json` with values like:

```json
{
"SMOKE_TEST_EMAIL_INBOX_URL": "http://localhost:1111/test-email-inbox",
"SMOKE_TEST_API_URL": "http://localhost:2222"
}
```
3 changes: 3 additions & 0 deletions smoke/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.json"
}
Loading