Skip to content

Commit

Permalink
smoke: introduce automated smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredh159 committed Dec 21, 2023
1 parent d969d44 commit 1ec58c7
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 8 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: smoke

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

jobs:
smoke:
name: smoke
runs-on: ubuntu-latest
steps:
- name: notify slack test
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_API_TOKEN }}
uses: pullreminders/slack-action@master
with:
args: '{\"channel\":\"G6007H2NM\",\"text\":\"testing, 1, 2, 3\"}'
- 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: notify slack
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_API_TOKEN }}
uses: pullreminders/slack-action@master
with:
args: '{\"channel\":\"G6007H2NM\",\"text\":\"Gertrude smoke test *FAILED*\"}'

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 }}
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"
}

0 comments on commit 1ec58c7

Please sign in to comment.