From 3ef1ba18b28658ae454c9d1f0fd9a4c3e437171a Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Fri, 21 Jun 2024 17:23:25 +0200 Subject: [PATCH] Improve Cypress tests --- .../pages/onboarding/vv/CheckoutAddress.vue | 9 ++++-- client/src/stores/user.ts | 2 ++ cypress/e2e/checkout-vv/checkout.cy.js | 28 ++++++++++++++++++- cypress/support/commands.js | 20 +++++++++++++ .../core/management/commands/cypress_reset.py | 6 ++++ server/vbv_lernwelt/core/serializers.py | 20 ++++++++++++- 6 files changed, 81 insertions(+), 4 deletions(-) diff --git a/client/src/pages/onboarding/vv/CheckoutAddress.vue b/client/src/pages/onboarding/vv/CheckoutAddress.vue index 952d96d0..7aea4499 100644 --- a/client/src/pages/onboarding/vv/CheckoutAddress.vue +++ b/client/src/pages/onboarding/vv/CheckoutAddress.vue @@ -184,7 +184,10 @@ async function saveAddress() { typedProfileData.organisation_country = countries.value.find( (c) => c.country_code === organisation_country_code ); - typedProfileData.phone_number = normalizeSwissPhoneNumber(phone_number); + + if (phone_number) { + typedProfileData.phone_number = normalizeSwissPhoneNumber(phone_number); + } await user.updateUserProfile(typedProfileData); } @@ -204,7 +207,9 @@ const executePayment = async () => { // anyway, so it seems fine to do it here. const fullHost = `${window.location.protocol}//${window.location.host}`; - address.value.phone_number = normalizeSwissPhoneNumber(address.value.phone_number); + if (address.value.phone_number) { + address.value.phone_number = normalizeSwissPhoneNumber(address.value.phone_number); + } itPost("/api/shop/vv/checkout/", { redirect_url: fullHost, diff --git a/client/src/stores/user.ts b/client/src/stores/user.ts index 4436c7b6..2c85dba7 100644 --- a/client/src/stores/user.ts +++ b/client/src/stores/user.ts @@ -81,6 +81,8 @@ const initialUserState: User = { postal_code: "", city: "", country: null, + birth_date: "", + phone_number: "", organisation_detail_name: "", organisation_street: "", organisation_street_number: "", diff --git a/cypress/e2e/checkout-vv/checkout.cy.js b/cypress/e2e/checkout-vv/checkout.cy.js index 4a396792..5039a762 100644 --- a/cypress/e2e/checkout-vv/checkout.cy.js +++ b/cypress/e2e/checkout-vv/checkout.cy.js @@ -94,7 +94,7 @@ describe("checkout.cy.js", () => { }); }); - it.only("can checkout and pay Versicherungsvermittlerin with Cembra invoice", () => { + it("can checkout and pay Versicherungsvermittlerin with Cembra invoice", () => { cy.get('[data-cy="start-vv"]').click(); // wähle "Deutsch" @@ -131,6 +131,32 @@ describe("checkout.cy.js", () => { cy.get('[data-cy="continue-pay"]').click(); + cy.loadExternalApiRequestLog("request_username", "empty@example.com").then((entry) => { + // ends with "/v1/transactions"" + expect(entry.api_url).to.contain("/v1/transactions"); + expect(entry.request_username).to.contain("empty@example.com"); + + expect(entry.api_request_data.amount).to.equal(32400); + expect(entry.api_request_data.currency).to.equal("CHF"); + expect(entry.api_request_data.autoSettle).to.equal(true); + + expect(entry.api_request_data.customer.firstName).to.equal("Flasche"); + expect(entry.api_request_data.customer.lastName).to.equal("Leer"); + expect(entry.api_request_data.customer.street).to.equal("Eggersmatt 32"); + expect(entry.api_request_data.customer.zipCode).to.equal("1719"); + expect(entry.api_request_data.customer.city).to.equal("Zumholz"); + expect(entry.api_request_data.customer.country).to.equal("CH"); + expect(entry.api_request_data.customer.type).to.equal("P"); + expect(entry.api_request_data.customer.phone).to.equal("+41792018586"); + + expect(entry.api_request_data.INT.repaymentType).to.equal(3); + expect(entry.api_request_data.INT.riskOwner).to.equal("IJ"); + expect(entry.api_request_data.INT.subtype).to.equal("INVOICE"); + expect(entry.api_request_data.INT.deviceFingerprintId).to.not.be.empty; + + expect(true).to.be.true; + }); + // check that results are stored on server cy.loadCheckoutInformation("user_id", TEST_USER_EMPTY_ID).then((ci) => { expect(ci.first_name).to.equal("Flasche"); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index eaf772c1..50dfdf30 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -138,6 +138,26 @@ Cypress.Commands.add("loadAssignmentCompletion", (key, value) => { ); }); +Cypress.Commands.add("loadSecurityRequestResponseLog", (key, value) => { + return loadObjectJson( + key, + value, + "vbv_lernwelt.core.models.SecurityRequestResponseLog", + "vbv_lernwelt.core.serializers.CypressSecurityRequestResponseLogSerializer", + true + ); +}); + +Cypress.Commands.add("loadExternalApiRequestLog", (key, value) => { + return loadObjectJson( + key, + value, + "vbv_lernwelt.core.models.ExternalApiRequestLog", + "vbv_lernwelt.core.serializers.CypressExternalApiRequestLogSerializer", + true + ); +}); + Cypress.Commands.add("loadFeedbackResponse", (key, value) => { return loadObjectJson( key, diff --git a/server/vbv_lernwelt/core/management/commands/cypress_reset.py b/server/vbv_lernwelt/core/management/commands/cypress_reset.py index 8d8ccce5..abfae404 100644 --- a/server/vbv_lernwelt/core/management/commands/cypress_reset.py +++ b/server/vbv_lernwelt/core/management/commands/cypress_reset.py @@ -3,6 +3,7 @@ from datetime import datetime import djclick as click from dateutil.relativedelta import relativedelta, TU from django.contrib.auth.hashers import make_password +from django.db import connection from django.utils import timezone from vbv_lernwelt.assignment.models import Assignment, AssignmentCompletion @@ -158,6 +159,11 @@ def command( password=make_password("test"), ) + cursor = connection.cursor() + cursor.execute("truncate core_securityrequestresponselog;") + cursor.execute("truncate core_externalapirequestlog;") + cursor.execute("truncate django_cache_table;") + if create_assignment_completion or create_assignment_evaluation: print("create assignment completion data for test course") create_test_assignment_submitted_data( diff --git a/server/vbv_lernwelt/core/serializers.py b/server/vbv_lernwelt/core/serializers.py index b1cd79df..3a656c71 100644 --- a/server/vbv_lernwelt/core/serializers.py +++ b/server/vbv_lernwelt/core/serializers.py @@ -3,7 +3,13 @@ from typing import List from rest_framework import serializers from rest_framework.renderers import JSONRenderer -from vbv_lernwelt.core.models import Country, Organisation, User +from vbv_lernwelt.core.models import ( + Country, + ExternalApiRequestLog, + Organisation, + SecurityRequestResponseLog, + User, +) from vbv_lernwelt.course.models import CourseSessionUser from vbv_lernwelt.course_session_group.models import CourseSessionGroup @@ -142,3 +148,15 @@ class OrganisationSerializer(serializers.ModelSerializer): return obj.name_it return obj.name_de + + +class CypressExternalApiRequestLogSerializer(serializers.ModelSerializer): + class Meta: + model = ExternalApiRequestLog + fields = "__all__" + + +class CypressSecurityRequestResponseLogSerializer(serializers.ModelSerializer): + class Meta: + model = SecurityRequestResponseLog + fields = "__all__"