mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 06:52:24 +00:00
reduce test code
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { addStub, removeStub } from "../support/mock";
|
||||
import { stub } from "../support/mock";
|
||||
|
||||
describe("login", () => {
|
||||
beforeEach(() => {
|
||||
removeStub("zitadel.session.v2alpha.SessionService", "CreateSession");
|
||||
addStub("zitadel.session.v2alpha.SessionService", "CreateSession", {
|
||||
stub("zitadel.session.v2alpha.SessionService", "CreateSession", {
|
||||
data: {
|
||||
details: {
|
||||
sequence: 859,
|
||||
@@ -17,8 +16,7 @@ describe("login", () => {
|
||||
},
|
||||
});
|
||||
|
||||
removeStub("zitadel.session.v2alpha.SessionService", "GetSession");
|
||||
addStub("zitadel.session.v2alpha.SessionService", "GetSession", {
|
||||
stub("zitadel.session.v2alpha.SessionService", "GetSession", {
|
||||
data: {
|
||||
session: {
|
||||
id: "221394658884845598",
|
||||
@@ -40,8 +38,7 @@ describe("login", () => {
|
||||
},
|
||||
});
|
||||
|
||||
removeStub("zitadel.settings.v2alpha.SessionService", "GetLoginSettings");
|
||||
addStub("zitadel.settings.v2alpha.SettingsService", "GetLoginSettings", {
|
||||
stub("zitadel.settings.v2alpha.SettingsService", "GetLoginSettings", {
|
||||
data: {
|
||||
settings: {
|
||||
passkeysType: 1,
|
||||
@@ -51,11 +48,7 @@ describe("login", () => {
|
||||
});
|
||||
describe("password login", () => {
|
||||
beforeEach(() => {
|
||||
removeStub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes"
|
||||
);
|
||||
addStub(
|
||||
stub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes",
|
||||
{
|
||||
@@ -69,51 +62,9 @@ describe("login", () => {
|
||||
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
|
||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
||||
});
|
||||
});
|
||||
|
||||
describe("passkey login", () => {
|
||||
describe("with passkey prompt", () => {
|
||||
beforeEach(() => {
|
||||
removeStub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes"
|
||||
);
|
||||
addStub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes",
|
||||
{
|
||||
data: {
|
||||
authMethodTypes: [2], // 2 for passwordless authentication
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
it("should redirect a user with passwordless authentication to /passkey/login", () => {
|
||||
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
|
||||
cy.location("pathname", { timeout: 10_000 }).should(
|
||||
"eq",
|
||||
"/passkey/login"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("password login with passkey prompt", () => {
|
||||
beforeEach(() => {
|
||||
removeStub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes"
|
||||
);
|
||||
addStub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes",
|
||||
{
|
||||
data: {
|
||||
authMethodTypes: [1], // 1 for password authentication
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
removeStub("zitadel.session.v2alpha.SessionService", "SetSession");
|
||||
addStub("zitadel.session.v2alpha.SessionService", "SetSession", {
|
||||
stub("zitadel.session.v2alpha.SessionService", "SetSession", {
|
||||
data: {
|
||||
details: {
|
||||
sequence: 859,
|
||||
@@ -135,3 +86,24 @@ describe("login", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("passkey login", () => {
|
||||
beforeEach(() => {
|
||||
stub(
|
||||
"zitadel.user.v2alpha.UserService",
|
||||
"ListAuthenticationMethodTypes",
|
||||
{
|
||||
data: {
|
||||
authMethodTypes: [2], // 2 for passwordless authentication
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
it("should redirect a user with passwordless authentication to /passkey/login", () => {
|
||||
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
|
||||
cy.location("pathname", { timeout: 10_000 }).should(
|
||||
"eq",
|
||||
"/passkey/login"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { addStub, removeStub } from "../support/mock";
|
||||
import { stub } from "../support/mock";
|
||||
|
||||
describe("register", () => {
|
||||
beforeEach(() => {
|
||||
removeStub("zitadel.user.v2alpha.UserService", "AddHumanUser");
|
||||
addStub("zitadel.user.v2alpha.UserService", "AddHumanUser", {
|
||||
stub("zitadel.user.v2alpha.UserService", "AddHumanUser", {
|
||||
data: {
|
||||
userId: "123",
|
||||
},
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { addStub, removeStub } from "../support/mock";
|
||||
import { stub } from "../support/mock";
|
||||
|
||||
describe("/verify", () => {
|
||||
it("redirects after successful email verification", () => {
|
||||
removeStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
||||
addStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
||||
stub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
||||
cy.visit("/verify?userID=123&code=abc&submit=true");
|
||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
|
||||
});
|
||||
it("shows an error if validation failed", () => {
|
||||
removeStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
||||
addStub("zitadel.user.v2alpha.UserService", "VerifyEmail", {
|
||||
stub("zitadel.user.v2alpha.UserService", "VerifyEmail", {
|
||||
code: 3,
|
||||
error: "error validating code",
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function removeStub(service: string, method: string) {
|
||||
function removeStub(service: string, method: string) {
|
||||
return cy.request({
|
||||
url: "http://localhost:22220/v1/stubs",
|
||||
method: "DELETE",
|
||||
@@ -9,7 +9,8 @@ export function removeStub(service: string, method: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function addStub(service: string, method: string, out?: any) {
|
||||
export function stub(service: string, method: string, out?: any) {
|
||||
removeStub(service, method)
|
||||
return cy.request({
|
||||
url: "http://localhost:22220/v1/stubs",
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user