Skip to content
Merged
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
17 changes: 8 additions & 9 deletions templates/cli/lib/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,26 +910,25 @@ export const questionsLogout: Question[] = [
{
type: "checkbox",
name: "accounts",
message: "Select accounts to logout from",
message: "Select accounts to log out",
validate: (value: any) => validateRequired("account", value),
choices() {
const sessions = globalConfig.getSessions();
const current = globalConfig.getCurrentSession();

const data: Choice[] = [];

const longestEmail = sessions.reduce((prev: any, current: any) =>
prev && (prev.email ?? "").length > (current.email ?? "").length
? prev
: current,
).email.length;

sessions.forEach((session: any) => {
if (session.email) {
const isCurrent = current === session.id;
const currentLabel = isCurrent
? ` ${chalk.green.bold("(current)")}`
: "";
data.push({
current: current === session.id,
current: isCurrent,
value: session.id,
name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold("current") : " ".repeat(6)} ${session.endpoint}`,
name: `${session.email}${currentLabel} - ${session.endpoint}`,
short: `${session.email}${isCurrent ? " (current)" : ""}`,
});
}
});
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ abstract class Base extends TestCase
'auth:session-legacy:passed',
'auth:session-has-auth:passed',
'auth:plan-session-logout:passed',
'auth:logout-question-choices:passed',
'auth:restore-current-session-fallback:passed',
'auth:poll-device-token-success:passed',
'auth:poll-device-token-retry:passed',
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/languages/cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const {
globalConfig,
} = require("./lib/config.ts");
const { listenForBrowserOpen } = require("./lib/auth/login.ts");
const { questionsLogout } = require("./lib/questions.ts");

const extractFirstValue = (output) => {
const firstLine =
Expand Down Expand Up @@ -902,6 +903,30 @@ async function runAuthChecks() {
assert.deepEqual(planSessionLogout(["b1"]), ["b1"]);
});

await authCheck("logout-question-choices", () => {
globalConfig.clear();
globalConfig.addSession("a1", {
endpoint: "https://cloud.appwrite.io/v1",
email: "a@b.com",
});
globalConfig.addSession("b1", {
endpoint: "http://localhost/v1",
email: "b@c.com",
});
globalConfig.setCurrentSession("b1");

const choices = questionsLogout[0].choices().map((choice) => ({
...choice,
name: stripAnsi(choice.name),
}));

assert.equal(choices[0].value, "b1");
assert.equal(choices[0].name, "b@c.com (current) - http://localhost/v1");
assert.equal(choices[0].short, "b@c.com (current)");
assert.equal(choices[1].name, "a@b.com - https://cloud.appwrite.io/v1");
assert.equal(choices[1].short, "a@b.com");
});

await authCheck("restore-current-session-fallback", () => {
globalConfig.clear();
globalConfig.addSession("s1", { endpoint: "http://localhost/v1" });
Expand Down
Loading