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

test(apps): fix dashboard/voucher/consent tests #4627

Merged
merged 21 commits into from
Oct 24, 2024
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
15 changes: 5 additions & 10 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ jobs:

- name: Buck2 build
run: |
nix develop -c buck2 build //core/api \
//core/api-ws-server \
//apps/dashboard \
//apps/consent \
//apps/pay \
//apps/admin-panel \
//apps/map \
//apps/voucher \
//core/api-keys \
//core/notifications
nix develop -c buck2 build \
//core/api //core/api-ws-server //core/api-trigger //core/api-exporter \
//apps/dashboard //apps/consent //apps/pay //apps/admin-panel //apps/map //apps/voucher \
//core/api-keys //core/notifications \
//bats/helpers/callback:run //bats/helpers/subscriber:run //bats/helpers/totp:generate

- name: Run bats tests
run: |
Expand Down
118 changes: 56 additions & 62 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@ on:
types: [opened, synchronize, labeled, unlabeled]

jobs:
tests:
name: execute via tilt
prepare:
name: prepare build args
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.prepare_args.outputs.matrix }}
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 15360
temp-reserve-mb: 12288
remove-dotnet: "true"
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Prepare tilt args from labels
id: prepare_args
run: |
ARGS=""
BUILD_ARGS=""
# Initialize variables
MATRIX="["

cat <<EOF > labels.json
${{ toJSON(github.event.pull_request.labels.*.name) }}
Expand All @@ -38,78 +30,80 @@ jobs:
LABELS=("${DEFAULT_LABELS[@]}")
fi

# Handle 'core' dependency
for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
core|dashboard|consent|pay|admin-panel|map|voucher)
BUILD_ARGS+=" //core/api:prod_build"
BUILD_ARGS+=" //core/notifications:notifications"
# Core dependencies that might be needed
CORE_DEPS="//core/api:prod_build //core/notifications:notifications //:node_modules"

break
;;
esac
done

# Handle root 'node_modules' dependency
# Process each label into a matrix entry
for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
dashboard|consent|pay|admin-panel|map|voucher)
BUILD_ARGS+=" "//:node_modules""
BUILD_ARGS=""

break
# Add core dependencies if needed
case "$LABEL" in
core|dashboard|consent|pay|admin-panel|map|voucher)
BUILD_ARGS+=" $CORE_DEPS"
;;
esac
done

# Handle 'consent' dependencies
for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
dashboard|voucher)
dashboard|voucher|consent)
BUILD_ARGS+=" //apps/consent:consent"
BUILD_ARGS+=" //core/api-keys:api-keys"

break
;;
esac
done

# Handle other labels
for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
core)
ARGS+=" $LABEL"
;;
esac

case "$LABEL" in
dashboard|consent|admin-panel|map|voucher)
ARGS+=" $LABEL"
BUILD_ARGS+=" //apps/$LABEL:$LABEL"
;;

core) ;;
pay)
ARGS+=" $LABEL"
BUILD_ARGS+=" //apps/$LABEL:$LABEL-ci"
;;
dashboard|admin-panel|map|voucher)
BUILD_ARGS+=" //apps/$LABEL:$LABEL"
;;
esac

# Add matrix entry if we have build args
if [ ! -z "$BUILD_ARGS" ]; then
if [ "$MATRIX" != "[" ]; then
MATRIX+=","
fi
MATRIX+="{\"component\":\"$LABEL\",\"build_args\":\"$BUILD_ARGS\"}"
fi
done

echo "Prepared args: $ARGS"
echo "Prepared build_args: $BUILD_ARGS"
echo "args=$ARGS" >> "$GITHUB_OUTPUT"
echo "build_args=$BUILD_ARGS" >> "$GITHUB_OUTPUT"
MATRIX+="]"
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"

build-and-test:
name: build and test ${{ matrix.component }}
needs: prepare
if: needs.prepare.outputs.matrix != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@master
with:
root-reserve-mb: 15360
temp-reserve-mb: 12288
remove-dotnet: "true"
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v14
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Build via buck2
if: steps.prepare_args.outputs.build_args != ''
run: nix develop -c buck2 build ${{ steps.prepare_args.outputs.build_args }}
run: nix develop -c buck2 build ${{ matrix.build_args }}
- name: Start deps and run tests via tilt
if: steps.prepare_args.outputs.args != ''
run: nix develop -c xvfb-run ./dev/bin/tilt-ci.sh ${{ steps.prepare_args.outputs.args }}
run: nix develop -c xvfb-run ./dev/bin/tilt-ci.sh ${{ matrix.component }}
- name: Prepare Tilt log
id: prepare_tilt_log
if: always()
run: |
TILT_LOG="dev/.e2e-tilt.log"
TARGET="dev/e2e-tilt.log"
TARGET="dev/e2e-tilt-${{ matrix.component }}.log"

if [ -f "$TILT_LOG" ]; then
mv "$TILT_LOG" "$TARGET"
Expand All @@ -121,5 +115,5 @@ jobs:
if: steps.prepare_tilt_log.outputs.prepared == 'true'
uses: actions/upload-artifact@v4
with:
name: Tilt log
path: dev/e2e-tilt.log
name: Tilt log - ${{ matrix.component }}
path: dev/e2e-tilt-${{ matrix.component }}.log
4 changes: 2 additions & 2 deletions apps/admin-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@svgr/webpack": "^8.1.0",
"@t3-oss/env-nextjs": "^0.7.1",
"graphql": "^16.8.1",
"next": "^14.2.12",
"next": "14.2.10",
"next-auth": "^4.24.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -63,4 +63,4 @@
"tailwindcss": "^3.3.3",
"ts-jest": "^29.1.1"
}
}
}
4 changes: 3 additions & 1 deletion apps/consent/app/login/email-login-server-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use server"
import { createHash } from "crypto"

import { redirect } from "next/navigation"
import { cookies, headers } from "next/headers"

Expand Down Expand Up @@ -77,7 +79,7 @@ export async function submitForm(
}

cookies().set(
encodeURIComponent(login_challenge),
createHash("md5").update(login_challenge).digest("hex"),
JSON.stringify({
loginType: LoginType.email,
loginId: emailCodeRequest,
Expand Down
38 changes: 20 additions & 18 deletions apps/consent/app/login/phone/server-actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use server"
import { cookies, headers } from "next/headers"
import { createHash } from "crypto"

import { redirect } from "next/navigation"
import { cookies, headers } from "next/headers"
import { isValidPhoneNumber } from "libphonenumber-js"

import {
Expand Down Expand Up @@ -73,6 +75,22 @@ export const getCaptchaChallenge = async (
}
}

if (env.CI || env.NODE_ENV === "development") {
const params = new URLSearchParams({
login_challenge,
})
cookies().set(
createHash("md5").update(login_challenge).digest("hex"),
JSON.stringify({
loginType: LoginType.phone,
value: phone,
remember: remember,
}),
{ secure: true },
)
redirect(`/login/verification?${params}`)
}

let res: {
id: string
challengeCode: string
Expand All @@ -94,22 +112,6 @@ export const getCaptchaChallenge = async (
const id = res.id
const challenge = res.challengeCode

if (env.NODE_ENV === "development") {
const params = new URLSearchParams({
login_challenge,
})
cookies().set(
encodeURIComponent(login_challenge),
JSON.stringify({
loginType: LoginType.phone,
value: phone,
remember: remember,
}),
{ secure: true },
)
redirect(`/login/verification?${params}`)
}

return {
error: false,
message: "success",
Expand Down Expand Up @@ -179,7 +181,7 @@ export const sendPhoneCode = async (
}

cookies().set(
encodeURIComponent(login_challenge),
createHash("md5").update(login_challenge).digest("hex"),
JSON.stringify({
loginType: LoginType.phone,
value: phone,
Expand Down
6 changes: 5 additions & 1 deletion apps/consent/app/login/verification/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use server"
import { createHash } from "crypto"

import { cookies } from "next/headers"

import VerificationForm from "./form"
Expand All @@ -18,7 +20,9 @@ interface VerificationProps {
const Verification = async ({ searchParams }: { searchParams: VerificationProps }) => {
const { login_challenge } = searchParams
// login_challenge is automatically decoded so we must encode it again to match cookie name
const cookieStore = cookies().get(encodeURIComponent(login_challenge))
const cookieStore = cookies().get(
createHash("md5").update(login_challenge).digest("hex"),
)

if (!cookieStore) {
throw new Error("Cannot find cookies")
Expand Down
45 changes: 0 additions & 45 deletions apps/consent/cypress/e2e/email-sign-in/login-email.cy.ts

This file was deleted.

48 changes: 48 additions & 0 deletions apps/consent/cypress/e2e/login-email.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { testData } from "../support/test-config"

describe("Account ID Test", () => {
it("Login email Test", () => {
const email = testData.EMAIL

cy.flushRedis()
cy.visit(testData.AUTHORIZATION_URL)
cy.location("search").should((search) => {
const params = new URLSearchParams(search)
expect(params.has("login_challenge")).to.be.true
})

cy.get("[data-testid=sign_in_with_phone_btn]")
.should("exist")
.should("be.visible")
.click()

cy.get("[data-testid=sign_in_with_email_btn]")
.should("exist")
.should("be.visible")
.click()

cy.get("[data-testid=email_id_input]")
.should("exist")
.should("be.visible")
.should("not.be.disabled")
.type(email)

cy.get("[data-testid=email_login_next_btn]")
.should("exist")
.should("be.visible")
.click()

cy.getOTP(email).then((code) => {
cy.get("[data-testid=verification_code_input]")
.should("exist")
.should("be.visible")
.should("not.be.disabled")
.type(code)

cy.get("[data-testid=submit_consent_btn]")
.should("exist")
.should("be.visible")
.should("not.be.disabled")
})
})
})
Loading
Loading