Skip to content

Commit 7409228

Browse files
committed
fix: update tests and fix errors on update profile
1 parent 0ddb71b commit 7409228

File tree

9 files changed

+93
-42
lines changed

9 files changed

+93
-42
lines changed

apps/client-e2e/src/profile-as-user.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,16 @@ test.describe('Work with profile as "User" role', () => {
8888
.locator('button[type=submit]')
8989
.click();
9090

91-
await setTimeout(7000);
91+
await page.waitForSelector('span.you-are-logged-in-as');
9292

9393
await expect(
9494
page.locator('nz-header').locator('[nz-submenu]').first()
9595
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
9696
});
9797

9898
test('sign out after sign-up', async () => {
99+
await page.waitForSelector('span.you-are-logged-in-as');
100+
99101
await expect(
100102
page.locator('nz-header').locator('[nz-submenu]').first()
101103
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
@@ -157,14 +159,16 @@ test.describe('Work with profile as "User" role', () => {
157159
.locator('button[type=submit]')
158160
.click();
159161

160-
await setTimeout(7000);
162+
await page.waitForSelector('span.you-are-logged-in-as');
161163

162164
await expect(
163165
page.locator('nz-header').locator('[nz-submenu]').first()
164166
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
165167
});
166168

167169
test('should change password in profile', async () => {
170+
await page.waitForSelector('span.you-are-logged-in-as');
171+
168172
await expect(
169173
page.locator('nz-header').locator('[nz-submenu]').first()
170174
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
@@ -234,10 +238,11 @@ test.describe('Work with profile as "User" role', () => {
234238
.locator('sso-profile-form')
235239
.locator('button[type=submit]')
236240
.click();
237-
await setTimeout(7000);
238241
});
239242

240243
test('sign out', async () => {
244+
await page.waitForSelector('span.you-are-logged-in-as');
245+
241246
await expect(
242247
page.locator('nz-header').locator('[nz-submenu]').first()
243248
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
@@ -299,7 +304,7 @@ test.describe('Work with profile as "User" role', () => {
299304
.locator('button[type=submit]')
300305
.click();
301306

302-
await setTimeout(7000);
307+
await page.waitForSelector('span.you-are-logged-in-as');
303308

304309
await expect(
305310
page.locator('nz-header').locator('[nz-submenu]').first()

apps/client-e2e/src/ru-validation-with-store-lang-in-db.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ test.describe('Validation with store lang in db (ru)', () => {
8787
.locator('sso-sign-up-form')
8888
.locator('button[type=submit]')
8989
.click();
90-
91-
await setTimeout(7000);
90+
await page.waitForSelector('span.you-are-logged-in-as');
9291

9392
await expect(
9493
page.locator('nz-header').locator('[nz-submenu]').first()

apps/client-e2e/src/timezone-profile-as-user.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ test.describe('Work with profile as "User" role (timezone', () => {
8989
.locator('sso-sign-up-form')
9090
.locator('button[type=submit]')
9191
.click();
92-
93-
await setTimeout(7000);
92+
await page.waitForSelector('span.you-are-logged-in-as');
9493

9594
await expect(
9695
page.locator('nz-header').locator('[nz-submenu]').first()
9796
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
9897
});
9998

10099
test('sign out after sign-up', async () => {
100+
await page.waitForSelector('span.you-are-logged-in-as');
101+
101102
await expect(
102103
page.locator('nz-header').locator('[nz-submenu]').first()
103104
).toContainText(`You are logged in as ${user.email.toLowerCase()}`);
@@ -159,7 +160,7 @@ test.describe('Work with profile as "User" role (timezone', () => {
159160
.locator('button[type=submit]')
160161
.click();
161162

162-
await setTimeout(7000);
163+
await page.waitForSelector('span.you-are-logged-in-as');
163164

164165
await expect(
165166
page.locator('nz-header').locator('[nz-submenu]').first()

apps/client-e2e/src/validation.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test.describe('Validation', () => {
8888
.locator('button[type=submit]')
8989
.click();
9090

91-
await setTimeout(7000);
91+
await page.waitForSelector('span.you-are-logged-in-as');
9292

9393
await expect(
9494
page.locator('nz-header').locator('[nz-submenu]').first()

apps/client/src/app/integrations/sso.configuration.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
SsoUserAndTokens,
2424
TokensService,
2525
} from '@nestjs-mod-sso/sso-angular';
26-
import { catchError, map, mergeMap, Observable, of } from 'rxjs';
26+
import { catchError, map, mergeMap, Observable, of, throwError } from 'rxjs';
2727

2828
export class SsoIntegrationConfiguration implements SsoConfiguration {
2929
constructor(
@@ -119,6 +119,7 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
119119
preferredUsername: string;
120120
roles: string[];
121121
picture: string | null;
122+
timezone: number | null;
122123
} {
123124
return {
124125
phoneNumber: result.phone,
@@ -127,6 +128,7 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
127128
preferredUsername: result.username || '',
128129
roles: result.roles ? result.roles.split(',') : [],
129130
picture: result.picture,
131+
timezone: result.timezone,
130132
};
131133
}
132134

@@ -140,22 +142,23 @@ export class SsoIntegrationConfiguration implements SsoConfiguration {
140142
mergeMap((picture) =>
141143
this.ssoRestService
142144
.ssoControllerProfile()
143-
.pipe(map((profile) => ({ ...profile, picture })))
145+
.pipe(map((profile) => ({ ...data, ...profile, picture })))
144146
),
145147
catchError(() => of(null)),
146148
mergeMap((profile) => {
147-
if (data && profile) {
148-
data = { ...data, ...(profile as SsoUpdateProfileInput) };
149+
if (!profile) {
150+
return throwError(() => new Error('profile not set'));
149151
}
150152
return this.ssoRestService.ssoControllerUpdateProfile({
151-
birthdate: data.birthdate,
152-
firstname: data.givenName,
153-
gender: data.gender,
154-
lastname: data.familyName,
155-
picture: data.picture,
156-
password: data.newPassword,
157-
confirmPassword: data.confirmNewPassword,
158-
oldPassword: data.oldPassword,
153+
birthdate: profile.birthdate,
154+
firstname: profile.givenName,
155+
gender: profile.gender,
156+
lastname: profile.familyName,
157+
picture: profile.picture,
158+
password: profile.newPassword,
159+
confirmPassword: profile.confirmNewPassword,
160+
oldPassword: profile.oldPassword,
161+
timezone: profile.timezone,
159162
});
160163
}),
161164
mergeMap(() => this.ssoRestService.ssoControllerProfile()),

apps/server-e2e/src/server/sso-profile.spec.ts

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RestClientHelper } from '@nestjs-mod-sso/testing';
33

44
describe('Sso profile (e2e)', () => {
55
let user: RestClientHelper<'strict'>;
6+
let project: RestClientHelper<'strict'>;
67

78
let userTokens: TokensResponse;
89

@@ -14,16 +15,45 @@ describe('Sso profile (e2e)', () => {
1415
'x-skip-throttle': process.env.SERVER_SSO_ADMIN_SECRET,
1516
},
1617
}).generateRandomUser();
18+
project = await new RestClientHelper({
19+
headers: {
20+
'x-skip-throttle': process.env.SERVER_SSO_ADMIN_SECRET,
21+
},
22+
}).generateRandomUser();
23+
});
24+
25+
it('Create project', async () => {
26+
const { data: createOneResult } = await user
27+
.getSsoApi()
28+
.ssoProjectsControllerCreateOne(
29+
{
30+
public: false,
31+
name: project.randomUser.uniqId,
32+
clientId: project.randomUser.id,
33+
clientSecret: project.randomUser.password,
34+
},
35+
{
36+
headers: { 'x-admin-secret': process.env.SERVER_SSO_ADMIN_SECRET },
37+
}
38+
);
39+
expect(createOneResult).toHaveProperty('id');
1740
});
1841

1942
it('Sign-up', async () => {
20-
const { data: signUpResult } = await user.getSsoApi().ssoControllerSignUp({
21-
username: user.randomUser.username,
22-
email: user.randomUser.email,
23-
password: user.randomUser.password,
24-
confirmPassword: user.randomUser.password,
25-
fingerprint: user.randomUser.id,
26-
});
43+
const { data: signUpResult } = await user.getSsoApi().ssoControllerSignUp(
44+
{
45+
username: user.randomUser.username,
46+
email: user.randomUser.email,
47+
password: user.randomUser.password,
48+
confirmPassword: user.randomUser.password,
49+
fingerprint: user.randomUser.id,
50+
},
51+
{
52+
headers: {
53+
'x-client-id': project.randomUser.id,
54+
},
55+
}
56+
);
2757
expect(signUpResult).toHaveProperty('accessToken');
2858
expect(signUpResult).toHaveProperty('refreshToken');
2959
expect(signUpResult).toHaveProperty('user');
@@ -35,8 +65,7 @@ describe('Sso profile (e2e)', () => {
3565
.ssoProjectsControllerFindMany(
3666
undefined,
3767
undefined,
38-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
39-
process.env.SERVER_SSO_DEFAULT_CLIENT_ID!,
68+
project.randomUser.id,
4069
undefined,
4170
{
4271
headers: { 'x-admin-secret': process.env.SERVER_SSO_ADMIN_SECRET },
@@ -74,11 +103,18 @@ describe('Sso profile (e2e)', () => {
74103
});
75104

76105
it('Sign-in', async () => {
77-
const { data: signInResult } = await user.getSsoApi().ssoControllerSignIn({
78-
email: user.randomUser.email,
79-
password: user.randomUser.password,
80-
fingerprint: user.randomUser.id,
81-
});
106+
const { data: signInResult } = await user.getSsoApi().ssoControllerSignIn(
107+
{
108+
email: user.randomUser.email,
109+
password: user.randomUser.password,
110+
fingerprint: user.randomUser.id,
111+
},
112+
{
113+
headers: {
114+
'x-client-id': project.randomUser.id,
115+
},
116+
}
117+
);
82118
expect(signInResult).toHaveProperty('accessToken');
83119
expect(signInResult).toHaveProperty('refreshToken');
84120
expect(signInResult).toHaveProperty('user');
@@ -93,9 +129,10 @@ describe('Sso profile (e2e)', () => {
93129
...(userTokens.accessToken
94130
? { Authorization: `Bearer ${userTokens.accessToken}` }
95131
: {}),
132+
'x-client-id': project.randomUser.id,
96133
},
97134
});
98-
const { data: updateProfileResult } = await user
135+
const { data: updatedProfileResult } = await user
99136
.getSsoApi()
100137
.ssoControllerUpdateProfile(
101138
{
@@ -110,6 +147,7 @@ describe('Sso profile (e2e)', () => {
110147
...(userTokens.accessToken
111148
? { Authorization: `Bearer ${userTokens.accessToken}` }
112149
: {}),
150+
'x-client-id': project.randomUser.id,
113151
},
114152
}
115153
);
@@ -135,7 +173,7 @@ describe('Sso profile (e2e)', () => {
135173
expect(profileResult.updatedAt).toBeDefined();
136174
expect(profileResult.createdAt).not.toEqual(profileResult.updatedAt);
137175

138-
expect(updateProfileResult).toMatchObject({
176+
expect(updatedProfileResult).toMatchObject({
139177
id: profileResult.id,
140178
email: user.randomUser.email,
141179
phone: null,
@@ -153,7 +191,7 @@ describe('Sso profile (e2e)', () => {
153191
createdAt: profileResult.createdAt,
154192
// updatedAt: '2025-02-26T06:57:00.953Z',
155193
});
156-
expect(updateProfileResult.updatedAt).toBeDefined();
157-
expect(profileResult.updatedAt).not.toEqual(updateProfileResult.updatedAt);
194+
expect(updatedProfileResult.updatedAt).toBeDefined();
195+
expect(profileResult.updatedAt).not.toEqual(updatedProfileResult.updatedAt);
158196
});
159197
});

0 commit comments

Comments
 (0)