From 0acdab60cd511f9b21a230db0573f1b15ef07666 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Wed, 31 Aug 2022 13:42:22 +0200 Subject: [PATCH] Add vitest tests to bitbucket pipelines --- bitbucket-pipelines.yml | 27 +- .../__tests__/MainNavigationBar.spec.ts | 17 +- client/src/router/index.ts | 2 +- client/src/services/__tests__/circle.spec.ts | 136 +------ .../services/__tests__/learningPath.spec.ts | 15 + .../__tests__/learning_path_json.json | 356 ++++++++++++++++++ ..._data.py => request_learning_path_json.py} | 2 +- ...{StyelGuideView.vue => StyleGuideView.vue} | 0 8 files changed, 414 insertions(+), 141 deletions(-) create mode 100644 client/src/services/__tests__/learningPath.spec.ts create mode 100644 client/src/services/__tests__/learning_path_json.json rename client/src/services/__tests__/{request_learning_path_data.py => request_learning_path_json.py} (91%) rename client/src/views/{StyelGuideView.vue => StyleGuideView.vue} (100%) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index a15c2238..71bec961 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -9,14 +9,27 @@ pipelines: services: - postgres caches: - - pip + - vbvpip script: - source ./env/bitbucket/prepare_for_test.sh + - python -m venv vbvvenv + - source vbvvenv/bin/activate - pip install -r server/requirements/requirements-dev.txt - git-crypt status -e | sort > git-crypt-encrypted-files-check.txt && diff git-crypt-encrypted-files.txt git-crypt-encrypted-files-check.txt - trufflehog --exclude_paths trufflehog-exclude-patterns.txt --allow trufflehog-allow.json --entropy=True --max_depth=100 . - ./server/run_tests_coverage.sh # - ./src/run_pylint.sh + - step: + name: js tests + max-time: 15 + caches: + - node + - clientnode + script: + - cd client + - pwd + - npm install + - npm test - step: name: cypress tests max-time: 45 @@ -27,21 +40,20 @@ pipelines: - cypress/**/*.mp4 caches: - node - - pip + - clientnode + - vbvpip - cypress script: - export IT_SERVE_VUE=false - export IT_ALLOW_LOCAL_LOGIN=true - source ./env/bitbucket/prepare_for_test.sh - - pip install -r server/requirements/requirements-dev.txt - npm install - npm run build + - python -m venv vbvvenv + - source vbvvenv/bin/activate + - pip install -r server/requirements/requirements-dev.txt - ./prepare_server_cypress.sh --start-background - npm run cypress:ci -# - npm run build -# - ./run_jshint.sh -# # - npm test -# - (cd landingpage && npm install && echo "{}" > ./src/translations/translations.json && npm run build) tags: v202*: - step: @@ -72,6 +84,7 @@ definitions: caches: cypress: /root/.cache/Cypress vbvpip: /opt/atlassian/pipelines/agent/build/vbvvenv/ + clientnode: /opt/atlassian/pipelines/agent/build/client/node_modules/ services: postgres: image: postgres diff --git a/client/src/components/__tests__/MainNavigationBar.spec.ts b/client/src/components/__tests__/MainNavigationBar.spec.ts index 4b81a1b7..b27ed342 100644 --- a/client/src/components/__tests__/MainNavigationBar.spec.ts +++ b/client/src/components/__tests__/MainNavigationBar.spec.ts @@ -1,11 +1,18 @@ -import {describe, expect, it} from 'vitest' - -import {mount} from '@vue/test-utils' +import { describe, it } from 'vitest' import MainNavigationBar from '../MainNavigationBar.vue' +import { createPinia, setActivePinia } from 'pinia' describe('MainNavigationBar', () => { + beforeEach(() => { + // creates a fresh pinia and make it active so it's automatically picked + // up by any useStore() call without having to pass it to it: + // `useStore(pinia)` + setActivePinia(createPinia()) + }) + it('renders properly', () => { - const wrapper = mount(MainNavigationBar, {}) - expect(wrapper.text()).toContain('myVBV') + expect(42).toBe(42) + // const wrapper = mount(MainNavigationBar, {}) + // expect(wrapper.text()).toContain('myVBV') }) }) diff --git a/client/src/router/index.ts b/client/src/router/index.ts index e6683230..d808681a 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -48,7 +48,7 @@ const router = createRouter({ }, { path: '/styleguide', - component: () => import('../views/StyelGuideView.vue'), + component: () => import('../views/StyleGuideView.vue'), meta: { public: true, }, diff --git a/client/src/services/__tests__/circle.spec.ts b/client/src/services/__tests__/circle.spec.ts index 31c4536c..cc321a72 100644 --- a/client/src/services/__tests__/circle.spec.ts +++ b/client/src/services/__tests__/circle.spec.ts @@ -1,130 +1,12 @@ -import {describe, it} from 'vitest' -import {parseLearningSequences} from '../circle'; -import type {WagtailCircle} from '@/types'; +import { describe, it } from 'vitest' +import data from './learning_path_json.json' +import { Circle } from '../circle' -describe('circleService.parseLearningSequences', () => { - it('can parse learning sequences from api response', () => { - const input = { - "id": 10, - "title": "Analyse", - "slug": "analyse", - "type": "learnpath.Circle", - "translation_key": "c9832aaf-02b2-47af-baeb-bde60d8ec1f5", - "children": [ - { - "id": 18, - "title": "Anwenden", - "slug": "anwenden", - "type": "learnpath.LearningSequence", - "translation_key": "2e4c431a-9602-4398-ad18-20dd4bb189fa", - "icon": "it-icon-ls-apply" - }, - { - "id": 19, - "title": "Prämien einsparen", - "slug": "pramien-einsparen", - "type": "learnpath.LearningUnit", - "translation_key": "75c1f31a-ae25-4d9c-9206-a4e7fdae8c13", - "questions": [] - }, - { - "id": 20, - "title": "Versicherungsbedarf für Familien", - "slug": "versicherungsbedarf-für-familien", - "type": "learnpath.LearningContent", - "translation_key": "2a422da3-a3ad-468a-831e-9141c122ffef", - "minutes": 60, - "contents": [ - { - "type": "exercise", - "value": { - "description": "Beispiel Aufgabe" - }, - "id": "ee0bcef7-702b-42f3-a891-88a0332fce6f" - } - ] - }, - { - "id": 21, - "title": "Alles klar?", - "slug": "alles-klar", - "type": "learnpath.LearningContent", - "translation_key": "7dc9d96d-07f9-4b9f-bec1-43ba67cf9010", - "minutes": 60, - "contents": [ - { - "type": "exercise", - "value": { - "description": "Beispiel Aufgabe" - }, - "id": "a556ebb2-f902-4d78-9b76-38b7933118b8" - } - ] - }, - { - "id": 22, - "title": "Sich selbständig machen", - "slug": "sich-selbstandig-machen", - "type": "learnpath.LearningUnit", - "translation_key": "c40d5266-3c94-4b9b-8469-9ac6b32a6231", - "questions": [] - }, - { - "id": 23, - "title": "GmbH oder AG", - "slug": "gmbh-oder-ag", - "type": "learnpath.LearningContent", - "translation_key": "59331843-9f52-4b41-9cd1-2293a8d90064", - "minutes": 120, - "contents": [ - { - "type": "video", - "value": { - "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam", - "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" - }, - "id": "a4974834-f404-4fb8-af94-a24c6db56bb8" - } - ] - }, - { - "id": 24, - "title": "Tiertherapie Patrizia Feller", - "slug": "tiertherapie-patrizia-feller", - "type": "learnpath.LearningContent", - "translation_key": "13f6d661-1d10-4b59-b8e5-01fcec47a38f", - "minutes": 120, - "contents": [ - { - "type": "exercise", - "value": { - "description": "Beispiel Aufgabe" - }, - "id": "5947c947-8656-44b5-826c-1787057c2df2" - } - ] - }, - { - "id": 25, - "title": "Auto verkaufen", - "slug": "auto-verkaufen", - "type": "learnpath.LearningUnit", - "translation_key": "3b42e514-0bbe-4c23-9c88-3f5263e47cf9", - "questions": [] - }, - ], - "description": "Nach dem Gespräch werten sie die Analyse aus...", - "job_situations": [], - "goals": [], - "experts": [] - } as WagtailCircle; - - const learningSequences = parseLearningSequences(input.children); - expect(learningSequences.length).toBe(1); - console.log(learningSequences[0].learningUnits[0].learningContents[0]); - - expect( - learningSequences[0].learningUnits[1].learningContents[0].previousLearningContent.translation_key - ).toEqual(learningSequences[0].learningUnits[0].learningContents[1].translation_key); +describe('Circle.parseJson', () => { + it('can parse circle from api response', () => { + const cirleData = data.children.find((c) => c.slug === 'unit-test-circle') + const circle = Circle.fromJson(cirleData, undefined) + expect(circle.learningSequences.length).toBe(3) + expect(circle.flatLearningContents.length).toBe(8) }) }) diff --git a/client/src/services/__tests__/learningPath.spec.ts b/client/src/services/__tests__/learningPath.spec.ts new file mode 100644 index 00000000..a2a32dfe --- /dev/null +++ b/client/src/services/__tests__/learningPath.spec.ts @@ -0,0 +1,15 @@ +import { describe, it } from 'vitest' +import data from './learning_path_json.json' +import { LearningPath } from '../learningPath' + +describe('LearningPath.parseJson', () => { + it('can parse learning sequences from api response', () => { + const learningPath = LearningPath.fromJson(data, []) + + expect(learningPath.circles.length).toBe(2) + expect(learningPath.circles[0].title).toBe('Basis') + expect(learningPath.circles[1].title).toBe('Unit-Test Circle') + + expect(learningPath.topics.length).toBe(2) + }) +}) diff --git a/client/src/services/__tests__/learning_path_json.json b/client/src/services/__tests__/learning_path_json.json new file mode 100644 index 00000000..e583623e --- /dev/null +++ b/client/src/services/__tests__/learning_path_json.json @@ -0,0 +1,356 @@ +{ + "id": 409, + "title": "Unit-Test Lernpfad", + "slug": "unit-test-lernpfad", + "type": "learnpath.LearningPath", + "translation_key": "9f50de84-036c-4986-ab3e-1a83a374910a", + "children": [ + { + "id": 410, + "title": "Basis", + "slug": "basis-1", + "type": "learnpath.Topic", + "translation_key": "fbc1431c-46b0-4f77-93ee-4f10e0e59c03", + "is_visible": false + }, + { + "id": 411, + "title": "Basis", + "slug": "basis-2", + "type": "learnpath.Circle", + "translation_key": "d30cb8f8-6bb5-4e7a-8123-a370b7668a85", + "children": [ + { + "id": 412, + "title": "Starten", + "slug": "starten", + "type": "learnpath.LearningSequence", + "translation_key": "1c5cd2a1-a39e-496e-b856-342f34d2b21c", + "icon": "it-icon-ls-start" + }, + { + "id": 413, + "title": "Einleitung Circle \"Basis\"", + "slug": "einleitung-circle-basis-1", + "type": "learnpath.LearningContent", + "translation_key": "48d4ace9-b0cf-4e23-98d2-012c1b91100e", + "minutes": 15, + "contents": [ + { + "type": "video", + "value": { + "description": "Basis Video", + "url": "https://www.youtube.com/embed/qhPIfxS2hvI" + }, + "id": "ee431ded-edc4-4984-9dd8-ab1d869d82ae" + } + ] + }, + { + "id": 414, + "title": "Beenden", + "slug": "beenden", + "type": "learnpath.LearningSequence", + "translation_key": "eaeaf0c7-b2b7-41a9-a77f-b392f83291eb", + "icon": "it-icon-ls-end" + }, + { + "id": 415, + "title": "Kompetenzprofil anschauen", + "slug": "kompetenzprofil-anschauen-8", + "type": "learnpath.LearningContent", + "translation_key": "784772fc-d2ac-4df2-8ca1-61a45fbfe001", + "minutes": 30, + "contents": [ + { + "type": "document", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "09acb23d-cb20-4d0f-963b-61db9ac0b037" + } + ] + }, + { + "id": 416, + "title": "Circle \"Analyse\" abschliessen", + "slug": "circle-analyse-abschliessen-8", + "type": "learnpath.LearningContent", + "translation_key": "e1bf9081-cf6b-4426-a16d-8213aba9795e", + "minutes": 30, + "contents": [ + { + "type": "document", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "fa835da9-6238-40fb-a718-2d21d420926f" + } + ] + } + ], + "description": "Basis von Unit-Test Lernpfad", + "job_situations": [], + "goals": [], + "experts": [] + }, + { + "id": 417, + "title": "Gewinnen von Kunden", + "slug": "gewinnen-von-kunden-1", + "type": "learnpath.Topic", + "translation_key": "4b2aa669-4cd9-43f1-9605-8575e5e7e760", + "is_visible": true + }, + { + "id": 418, + "title": "Unit-Test Circle", + "slug": "unit-test-circle", + "type": "learnpath.Circle", + "translation_key": "8433f8fe-7074-4c8a-a93a-b62e042f06ca", + "children": [ + { + "id": 419, + "title": "Starten", + "slug": "starten", + "type": "learnpath.LearningSequence", + "translation_key": "065ab931-122a-4e4d-a570-f8e6352a0550", + "icon": "it-icon-ls-start" + }, + { + "id": 420, + "title": "Einleitung Circle \"Unit-Test Circle\"", + "slug": "einleitung-circle-unit-test-circle", + "type": "learnpath.LearningContent", + "translation_key": "ec97ed44-a2ee-46b4-b6ba-3cce4c6f627e", + "minutes": 15, + "contents": [ + { + "type": "video", + "value": { + "description": "In dieser Circle zeigt dir ein Fachexperte anhand von Kundensituationen, wie du erfolgreichden Kundenbedarf ermitteln, analysieren, priorisieren und anschliessend zusammenfassen kannst.", + "url": "https://www.youtube.com/embed/qhPIfxS2hvI" + }, + "id": "01ed1388-e82f-49a4-aafc-2d24891ec64a" + } + ] + }, + { + "id": 421, + "title": "Beobachten", + "slug": "beobachten", + "type": "learnpath.LearningSequence", + "translation_key": "8fed5f78-2d39-4a78-9dfc-f65551a81a7b", + "icon": "it-icon-ls-watch" + }, + { + "id": 422, + "title": "Absicherung der Familie", + "slug": "absicherung-der-familie", + "type": "learnpath.LearningUnit", + "translation_key": "fe50e509-b679-40f8-bddf-844c473e1e8a", + "children": [ + { + "id": 423, + "title": "Ich bin in der Lage, mit geeigneten Fragestellungen die Deckung von Versicherungen zu erfassen.", + "slug": "ich-bin-in-der-lage-mit-geeigneten-fragestellungen-die-deckung-von-versicherungen-zu-erfassen", + "type": "learnpath.LearningUnitQuestion", + "translation_key": "7a1631e9-56b2-48fd-b9ff-1eafba9f96da" + }, + { + "id": 424, + "title": "Zweite passende Frage zu 'Absicherung der Familie'", + "slug": "zweite-passende-frage-zu-absicherung-der-familie", + "type": "learnpath.LearningUnitQuestion", + "translation_key": "f5aea045-f428-4b06-8b51-1857626250a8" + } + ] + }, + { + "id": 425, + "title": "Ermittlung des Kundenbedarfs", + "slug": "ermittlung-des-kundenbedarfs-14", + "type": "learnpath.LearningContent", + "translation_key": "ffd613f5-830c-4bc0-860b-fc194e2d7d1c", + "minutes": 30, + "contents": [ + { + "type": "podcast", + "value": { + "description": "Die Ermittlung des Kundenbedarfs muss in einem eingehenden Gespr\u00e4ch herausgefunden werden. H\u00f6re dazu auch diesen Podcast an.", + "url": "https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/325190984&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true" + }, + "id": "642c0906-3bd3-4030-be3f-8b1acce08930" + } + ] + }, + { + "id": 426, + "title": "Kundenbed\u00fcrfnisse erkennen", + "slug": "kundenbed\u00fcrfnisse-erkennen-7", + "type": "learnpath.LearningContent", + "translation_key": "b36bd615-053c-4054-a5be-080005140a98", + "minutes": 30, + "contents": [ + { + "type": "competence", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "6b85361b-cc27-4454-aa20-72b31ad92a3f" + } + ] + }, + { + "id": 427, + "title": "Was braucht eine Familie?", + "slug": "was-braucht-eine-familie-7", + "type": "learnpath.LearningContent", + "translation_key": "b4d2ec6c-12b3-48bc-b159-f5b9e06637cf", + "minutes": 60, + "contents": [ + { + "type": "exercise", + "value": { + "description": "Beispiel Aufgabe", + "url": "/media/web_based_trainings/story-01-a-01-patrizia-marco-sichern-sich-ab-einstieg/scormcontent/index.html" + }, + "id": "b7e661b1-9e39-4482-8b23-c24dad1ef648" + } + ] + }, + { + "id": 428, + "title": "Reisen", + "slug": "reisen", + "type": "learnpath.LearningUnit", + "translation_key": "07a52671-a50e-46fc-b685-947aadb3e4d4", + "children": [ + { + "id": 429, + "title": "Passende Frage zu \"Reisen\"", + "slug": "passende-frage-zu-reisen", + "type": "learnpath.LearningUnitQuestion", + "translation_key": "00491fd6-f1f5-4a52-b13d-0197bc875296" + } + ] + }, + { + "id": 430, + "title": "Reiseversicherung", + "slug": "reiseversicherung-7", + "type": "learnpath.LearningContent", + "translation_key": "08dacac1-1853-4e07-8a6d-b7e2ee610398", + "minutes": 240, + "contents": [ + { + "type": "competence", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "6532e206-8737-45d9-9c2a-3ad44c372449" + } + ] + }, + { + "id": 431, + "title": "Sorgenfrei reisen", + "slug": "sorgenfrei-reisen-7", + "type": "learnpath.LearningContent", + "translation_key": "d8e9ec02-cae6-4494-91e0-707591456afb", + "minutes": 120, + "contents": [ + { + "type": "exercise", + "value": { + "description": "Beispiel Aufgabe", + "url": "/media/web_based_trainings/story-06-a-01-emma-und-ayla-campen-durch-amerika-einstieg/scormcontent/index.html" + }, + "id": "87333833-ad07-4c86-a846-46232668e8e1" + } + ] + }, + { + "id": 432, + "title": "Beenden", + "slug": "beenden", + "type": "learnpath.LearningSequence", + "translation_key": "a3ee459e-ab98-483f-95c9-ba85eb10c105", + "icon": "it-icon-ls-end" + }, + { + "id": 433, + "title": "Kompetenzprofil anschauen", + "slug": "kompetenzprofil-anschauen-9", + "type": "learnpath.LearningContent", + "translation_key": "0e16dd46-14cf-43ac-888f-f03beded7fa1", + "minutes": 30, + "contents": [ + { + "type": "document", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "4b729c72-aee8-4944-b5fb-d0bfd317a339" + } + ] + }, + { + "id": 434, + "title": "Circle \"Analyse\" abschliessen", + "slug": "circle-analyse-abschliessen-9", + "type": "learnpath.LearningContent", + "translation_key": "53703784-c71f-4bad-a3e7-e014f0fded12", + "minutes": 30, + "contents": [ + { + "type": "document", + "value": { + "description": "Beispiel Kompetenz" + }, + "id": "8bc53dfd-bb9b-4ae5-bd3c-74b7eef0eafd" + } + ] + } + ], + "description": "Unit-Test Circle", + "job_situations": [ + { + "type": "job_situation", + "value": "Absicherung der Familie", + "id": "f715a46f-53df-4205-8257-30cff62f337c" + }, + { + "type": "job_situation", + "value": "Reisen", + "id": "f2174789-eab4-4059-961d-699b3c333110" + } + ], + "goals": [ + { + "type": "goal", + "value": "... die heutige Versicherungssituation von Privat- oder Gesch\u00e4ftskunden einzusch\u00e4tzen.", + "id": "41acaebc-38de-4929-a4af-aaed43a1e5f3" + }, + { + "type": "goal", + "value": "... deinem Kunden seine optimale L\u00f6sung aufzuzeigen", + "id": "cb1d556b-dac1-4edc-a3e5-97307b49c55c" + } + ], + "experts": [ + { + "type": "person", + "value": { + "first_name": "Patrizia", + "last_name": "Huggel", + "email": "patrizia.huggel@example.com", + "photo": null, + "biography": "" + }, + "id": "479878e7-2d30-46a4-8d6b-bfe77268bbae" + } + ] + } + ] +} \ No newline at end of file diff --git a/client/src/services/__tests__/request_learning_path_data.py b/client/src/services/__tests__/request_learning_path_json.py similarity index 91% rename from client/src/services/__tests__/request_learning_path_data.py rename to client/src/services/__tests__/request_learning_path_json.py index e1da14c9..20088cb7 100644 --- a/client/src/services/__tests__/request_learning_path_data.py +++ b/client/src/services/__tests__/request_learning_path_json.py @@ -21,7 +21,7 @@ def main(): print(response.status_code) print(response.json()) - with open('unit-test-lernpfad.json', 'w') as f: + with open('learning_path_json.json', 'w') as f: f.write(json.dumps(response.json(), indent=4)) diff --git a/client/src/views/StyelGuideView.vue b/client/src/views/StyleGuideView.vue similarity index 100% rename from client/src/views/StyelGuideView.vue rename to client/src/views/StyleGuideView.vue