Skip to content
Closed
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
44 changes: 44 additions & 0 deletions .github/workflows/database-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'ci
on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: supabase/setup-cli@v1
with:
version: latest
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: |
OUTPUT=$(supabase start)

NEXT_PUBLIC_SUPABASE_URL=$(echo "$OUTPUT" | awk -F': ' '/API URL/ {print $2}')
NEXT_PUBLIC_SUPABASE_ANON_KEY=$(echo "$OUTPUT" | awk -F': ' '/anon key/ {print $2}')
SUPABASE_SERVICE_ROLE_KEY=$(echo "$OUTPUT" | awk -F': ' '/service_role key/ {print $2}')

echo "NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL" >> ./frontend/.env
echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY" >> ./frontend/.env
echo "SUPABASE_SERVICE_ROLE_KEY=$SUPABASE_SERVICE_ROLE_KEY" >> ./frontend/.env
- run: supabase db lint
- run: supabase test db
- run: |
echo "NEXT_PUBLIC_LOGFLARE_CLIENT_TOKEN=123" >> ./frontend/.env
echo "NEXT_PUBLIC_LOGFLARE_API_TOKEN=123" >> ./frontend/.env
echo "NEXT_PUBLIC_TURNSTILE_SITE_KEY=1x00000000000000000000AA" >> ./frontend/.env
echo "TURNSTILE_SECRET_KEY=123" >> ./frontend/.env
- run: npm ci
working-directory: ./frontend
- run: npm run build
working-directory: ./frontend
- run: |
nohup npm start -- --port 3000 > next.log 2>&1 &
working-directory: ./frontend
- run: npx --yes wait-on http://localhost:3000
- run: npm ci
working-directory: ./e2e
- run: npm run test:e2e
working-directory: ./e2e
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ jspm_packages

backend/apl_config_gend.yml
backend/users_id.csv
supabase

**.DS_Store
70 changes: 70 additions & 0 deletions backend/backend/load_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import argparse
from datetime import datetime

from backend.enums.question_type import QuestionType
from backend.logger import Logger
from loguru import logger
from backend.utils.consts import REGEX_JS, REGEX_TO_DESCRIPTION
from backend.utils.utils_datetime import convert_to_timezone
from backend.utils.utils_file import read_yaml_file
from backend.utils.utils_supabase import init_supabase
from backend.validate_config import (
DEFAULT_PARAMS,
MANDATORY_PARAMS,
OPTIONAL_PARAMS,
QUESTION_TYPES_DB_TABLE,
run_structure_checks,
)



def add_test_user(supabase):
users = [dict(mail="[email protected]", role=1), dict(mail="[email protected]", role=2)]
password = "123456"

for user in users:
try:
res_user = supabase.auth.sign_up({"email": user["mail"], "password": password})
user_id = res_user.user.id
supabase.table("application_table").insert({"userid": user_id}).execute()
supabase.table("user_profiles_table").insert(
{"userid": user_id, "userrole": user["role"], "isactive": True}
).execute()
except Exception as e:
logger.error(f"Error creating user {user['mail']}: {e}")

print("Done")

def load_fixtures(config_file_path: str, env_file_path: str):
supabase = init_supabase(env_file_path)

add_test_user(supabase)



def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Script to setup the supabase database using the config file"
)
parser.add_argument(
"--config",
help="Path to the yaml config file",
type=str,
default="backend/apl_config_gend_all_phases.yml",
dest="config_file_path",
required=False,
)
parser.add_argument(
"--env_file",
help="Path to the .env file",
type=str,
default=None,
dest="env_file_path",
required=False,
)
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()
load_fixtures(**vars(args))
4 changes: 2 additions & 2 deletions backend/backend/sql/bucket_policies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ CREATE POLICY "all_cmds" ON "storage"."objects"
AS PERMISSIVE FOR ALL
TO authenticated
USING (((auth.uid() = owner)))
WITH CHECK (((auth.uid() = owner)))
WITH CHECK (((auth.uid() = owner)));

CREATE POLICY "all_cmds" ON "storage"."buckets"
AS PERMISSIVE FOR ALL
TO authenticated
USING (((auth.uid() = owner)))
WITH CHECK (((auth.uid() = owner)))
WITH CHECK (((auth.uid() = owner)));
9 changes: 9 additions & 0 deletions e2e/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
19 changes: 19 additions & 0 deletions e2e/cypress/e2e/registration.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('registration', () => {
it('passes', () => {
cy.visit('http://localhost:3000')
cy.url().should('contain', 'login')

cy.contains('button', 'Registrieren').click()

const password = 'Password1!'

cy.get("#email").type("[email protected]")
cy.get("#password").type(password)
cy.get("#confirm-password").type(password)
cy.get('#confirm-legal').check()

cy.get('.apl-button-expanded').click()

cy.contains('Wir haben dir eine Email geschickt!')
})
})
5 changes: 5 additions & 0 deletions e2e/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions e2e/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
Loading