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", () => {
|
describe("login", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
removeStub("zitadel.session.v2alpha.SessionService", "CreateSession");
|
stub("zitadel.session.v2alpha.SessionService", "CreateSession", {
|
||||||
addStub("zitadel.session.v2alpha.SessionService", "CreateSession", {
|
|
||||||
data: {
|
data: {
|
||||||
details: {
|
details: {
|
||||||
sequence: 859,
|
sequence: 859,
|
||||||
@@ -17,8 +16,7 @@ describe("login", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
removeStub("zitadel.session.v2alpha.SessionService", "GetSession");
|
stub("zitadel.session.v2alpha.SessionService", "GetSession", {
|
||||||
addStub("zitadel.session.v2alpha.SessionService", "GetSession", {
|
|
||||||
data: {
|
data: {
|
||||||
session: {
|
session: {
|
||||||
id: "221394658884845598",
|
id: "221394658884845598",
|
||||||
@@ -40,8 +38,7 @@ describe("login", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
removeStub("zitadel.settings.v2alpha.SessionService", "GetLoginSettings");
|
stub("zitadel.settings.v2alpha.SettingsService", "GetLoginSettings", {
|
||||||
addStub("zitadel.settings.v2alpha.SettingsService", "GetLoginSettings", {
|
|
||||||
data: {
|
data: {
|
||||||
settings: {
|
settings: {
|
||||||
passkeysType: 1,
|
passkeysType: 1,
|
||||||
@@ -51,11 +48,7 @@ describe("login", () => {
|
|||||||
});
|
});
|
||||||
describe("password login", () => {
|
describe("password login", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
removeStub(
|
stub(
|
||||||
"zitadel.user.v2alpha.UserService",
|
|
||||||
"ListAuthenticationMethodTypes"
|
|
||||||
);
|
|
||||||
addStub(
|
|
||||||
"zitadel.user.v2alpha.UserService",
|
"zitadel.user.v2alpha.UserService",
|
||||||
"ListAuthenticationMethodTypes",
|
"ListAuthenticationMethodTypes",
|
||||||
{
|
{
|
||||||
@@ -69,15 +62,33 @@ describe("login", () => {
|
|||||||
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
|
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
|
||||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
||||||
});
|
});
|
||||||
|
describe("with passkey prompt", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
stub("zitadel.session.v2alpha.SessionService", "SetSession", {
|
||||||
|
data: {
|
||||||
|
details: {
|
||||||
|
sequence: 859,
|
||||||
|
changeDate: "2023-07-04T07:58:20.126Z",
|
||||||
|
resourceOwner: "220516472055706145",
|
||||||
|
},
|
||||||
|
sessionToken:
|
||||||
|
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
|
||||||
|
challenges: undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("should prompt a user to setup passwordless authentication if passkey is allowed in the login settings", () => {
|
||||||
|
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
|
||||||
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
||||||
|
cy.get('input[type="password"]').focus().type("MyStrongPassword!1");
|
||||||
|
cy.get('button[type="submit"]').click();
|
||||||
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/passkey/add");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("passkey login", () => {
|
describe("passkey login", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
removeStub(
|
stub(
|
||||||
"zitadel.user.v2alpha.UserService",
|
|
||||||
"ListAuthenticationMethodTypes"
|
|
||||||
);
|
|
||||||
addStub(
|
|
||||||
"zitadel.user.v2alpha.UserService",
|
"zitadel.user.v2alpha.UserService",
|
||||||
"ListAuthenticationMethodTypes",
|
"ListAuthenticationMethodTypes",
|
||||||
{
|
{
|
||||||
@@ -95,43 +106,4 @@ describe("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", {
|
|
||||||
data: {
|
|
||||||
details: {
|
|
||||||
sequence: 859,
|
|
||||||
changeDate: "2023-07-04T07:58:20.126Z",
|
|
||||||
resourceOwner: "220516472055706145",
|
|
||||||
},
|
|
||||||
sessionToken:
|
|
||||||
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
|
|
||||||
challenges: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("should prompt a user to setup passwordless authentication if passkey is allowed in the login settings", () => {
|
|
||||||
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
|
|
||||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
|
||||||
cy.get('input[type="password"]').focus().type("MyStrongPassword!1");
|
|
||||||
cy.get('button[type="submit"]').click();
|
|
||||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/passkey/add");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { addStub, removeStub } from "../support/mock";
|
import { stub } from "../support/mock";
|
||||||
|
|
||||||
describe("register", () => {
|
describe("register", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
removeStub("zitadel.user.v2alpha.UserService", "AddHumanUser");
|
stub("zitadel.user.v2alpha.UserService", "AddHumanUser", {
|
||||||
addStub("zitadel.user.v2alpha.UserService", "AddHumanUser", {
|
|
||||||
data: {
|
data: {
|
||||||
userId: "123",
|
userId: "123",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import { addStub, removeStub } from "../support/mock";
|
import { stub } from "../support/mock";
|
||||||
|
|
||||||
describe("/verify", () => {
|
describe("/verify", () => {
|
||||||
it("redirects after successful email verification", () => {
|
it("redirects after successful email verification", () => {
|
||||||
removeStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
stub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
||||||
addStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
|
||||||
cy.visit("/verify?userID=123&code=abc&submit=true");
|
cy.visit("/verify?userID=123&code=abc&submit=true");
|
||||||
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
|
||||||
});
|
});
|
||||||
it("shows an error if validation failed", () => {
|
it("shows an error if validation failed", () => {
|
||||||
removeStub("zitadel.user.v2alpha.UserService", "VerifyEmail");
|
stub("zitadel.user.v2alpha.UserService", "VerifyEmail", {
|
||||||
addStub("zitadel.user.v2alpha.UserService", "VerifyEmail", {
|
|
||||||
code: 3,
|
code: 3,
|
||||||
error: "error validating code",
|
error: "error validating code",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export function removeStub(service: string, method: string) {
|
function removeStub(service: string, method: string) {
|
||||||
return cy.request({
|
return cy.request({
|
||||||
url: "http://localhost:22220/v1/stubs",
|
url: "http://localhost:22220/v1/stubs",
|
||||||
method: "DELETE",
|
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({
|
return cy.request({
|
||||||
url: "http://localhost:22220/v1/stubs",
|
url: "http://localhost:22220/v1/stubs",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in New Issue
Block a user