Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit a11497e

Browse files
committed
tests: update tests messages
1 parent 836165b commit a11497e

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/commands/login/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe('loginCommand', () => {
163163
const mockUser = { email: 'user@example.com' };
164164
vi.mocked(loginWithToken).mockResolvedValue({ user: mockUser });
165165

166-
await loginCommand.parseAsync(['node', 'test']);
166+
await loginCommand.parseAsync(['node', 'test', '--region', 'eu']);
167167

168168
expect(password).toHaveBeenCalledWith(expect.objectContaining({
169169
message: 'Please enter your token:',
@@ -183,11 +183,11 @@ describe('loginCommand', () => {
183183
const mockUser = { email: 'test@example.com', friendly_name: 'Test User' };
184184
vi.mocked(loginWithToken).mockResolvedValue({ user: mockUser });
185185

186-
await loginCommand.parseAsync(['node', 'test', '--token', mockToken]);
186+
await loginCommand.parseAsync(['node', 'test', '--token', mockToken, '--region', 'eu']);
187187

188188
expect(loginWithToken).toHaveBeenCalledWith(mockToken, 'eu');
189189

190-
expect(konsola.ok).toHaveBeenCalledWith('Successfully logged in. Welcome Test User.', true);
190+
expect(konsola.ok).toHaveBeenCalledWith('Successfully logged in to region Europe (eu). Welcome Test User.', true);
191191
});
192192

193193
it('should login with a valid token in another region --region', async () => {
@@ -199,7 +199,7 @@ describe('loginCommand', () => {
199199

200200
expect(loginWithToken).toHaveBeenCalledWith(mockToken, 'us');
201201

202-
expect(konsola.ok).toHaveBeenCalledWith('Successfully logged in. Welcome Test User.', true);
202+
expect(konsola.ok).toHaveBeenCalledWith('Successfully logged in to region United States (us). Welcome Test User.', true);
203203
});
204204

205205
it('should throw an error for an invalid token', async () => {

src/commands/login/index.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const loginCommand = program
3434
.option(
3535
'-r, --region <region>',
3636
`The region you would like to work in. Please keep in mind that the region must match the region of your space. This region flag will be used for the other cli's commands. You can use the values: ${allRegionsText}.`,
37-
regions.EU,
3837
)
3938
.action(async (options: {
4039
token: string;
@@ -46,10 +45,6 @@ export const loginCommand = program
4645
// Command options
4746
const { token, region } = options;
4847

49-
if (!isRegion(region)) {
50-
handleError(new CommandError(`The provided region: ${region} is not valid. Please use one of the following values: ${Object.values(regions).join(' | ')}`));
51-
}
52-
5348
const { state, updateSession, persistCredentials, initializeSession } = session();
5449

5550
await initializeSession();
@@ -59,17 +54,34 @@ export const loginCommand = program
5954
return;
6055
}
6156

57+
if (region && !isRegion(region)) {
58+
handleError(new CommandError(`The provided region: ${region} is not valid. Please use one of the following values: ${Object.values(regions).join(' | ')}`));
59+
return;
60+
}
61+
6262
if (token) {
6363
const spinner = new Spinner({
6464
verbose: !isVitest,
65-
}).start(`Logging in with token`);
65+
});
6666
try {
67-
const { user } = await loginWithToken(token, region);
68-
updateSession(user.email, token, region);
69-
await persistCredentials(region);
67+
let userRegion = region;
68+
if (!userRegion) {
69+
userRegion = await select({
70+
message: 'Please select the region you would like to work in:',
71+
choices: Object.values(regions).map((region: RegionCode) => ({
72+
name: regionNames[region],
73+
value: region,
74+
})),
75+
default: regions.EU,
76+
});
77+
}
78+
spinner.start(`Logging in with token`);
79+
const { user } = await loginWithToken(token, userRegion);
80+
updateSession(user.email, token, userRegion);
81+
await persistCredentials(userRegion);
7082
spinner.succeed();
7183

72-
konsola.ok(`Successfully logged in. Welcome ${chalk.hex(colorPalette.PRIMARY)(user.friendly_name)}.`, true);
84+
konsola.ok(`Successfully logged in to region ${chalk.hex(colorPalette.PRIMARY)(`${regionNames[userRegion]} (${userRegion})`)}. Welcome ${chalk.hex(colorPalette.PRIMARY)(user.friendly_name)}.`, true);
7385
}
7486
catch (error) {
7587
spinner.failed();
@@ -96,7 +108,7 @@ export const loginCommand = program
96108
updateSession(user.email, userToken, region);
97109
await persistCredentials(region);
98110

99-
konsola.ok(`Successfully logged in. Welcome ${chalk.hex(colorPalette.PRIMARY)(user.friendly_name)}.`, true);
111+
konsola.ok(`Successfully logged in to region ${chalk.hex(colorPalette.PRIMARY)(`${regionNames[region]} (${region})`)}. Welcome ${chalk.hex(colorPalette.PRIMARY)(user.friendly_name)}.`, true);
100112
}
101113

102114
else {
@@ -123,6 +135,7 @@ export const loginCommand = program
123135
default: regions.EU,
124136
});
125137
}
138+
126139
spinner.start(`Logging in with email`);
127140
spinner.succeed();
128141
const response = await loginWithEmailAndPassword(userEmail, userPassword, userRegion);
@@ -143,7 +156,7 @@ export const loginCommand = program
143156
}
144157
await persistCredentials(region);
145158

146-
konsola.ok(`Successfully logged in. Welcome ${chalk.hex(colorPalette.PRIMARY)(userEmail)}.`, true);
159+
konsola.ok(`Successfully logged in to region ${chalk.hex(colorPalette.PRIMARY)(`${regionNames[userRegion]} (${userRegion})`)}. Welcome ${chalk.hex(colorPalette.PRIMARY)(userEmail)}.`, true);
147160
}
148161
}
149162
catch (error) {

0 commit comments

Comments
 (0)