Skip to content

Commit 0154166

Browse files
authored
add locale to user (#1363)
## Description adds `locale` to the User object, adds support for updating User locale ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [X] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent b6023aa commit 0154166

File tree

7 files changed

+30
-1
lines changed

7 files changed

+30
-1
lines changed

src/user-management/fixtures/list-users.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"updated_at": "2023-07-18T02:07:19.911Z",
1212
"email_verified": true,
1313
"profile_picture_url": "https://example.com/profile_picture.jpg",
14-
"last_sign_in_at": "2023-07-18T02:07:19.911Z"
14+
"last_sign_in_at": "2023-07-18T02:07:19.911Z",
15+
"locale": "en-US"
1516
}
1617
],
1718
"list_metadata": {

src/user-management/fixtures/user.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"email_verified": true,
1010
"profile_picture_url": "https://example.com/profile_picture.jpg",
1111
"last_sign_in_at": "2023-07-18T02:07:19.911Z",
12+
"locale": "en-US",
1213
"metadata": { "key": "value" }
1314
}

src/user-management/interfaces/update-user-options.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface UpdateUserOptions {
1010
passwordHash?: string;
1111
passwordHashType?: PasswordHashType;
1212
externalId?: string;
13+
locale?: string;
1314
metadata?: Record<string, string | null>;
1415
}
1516

@@ -22,5 +23,6 @@ export interface SerializedUpdateUserOptions {
2223
password_hash?: string;
2324
password_hash_type?: PasswordHashType;
2425
external_id?: string;
26+
locale?: string;
2527
metadata?: Record<string, string | null>;
2628
}

src/user-management/interfaces/user.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface User {
77
firstName: string | null;
88
lastName: string | null;
99
lastSignInAt: string | null;
10+
locale: string | null;
1011
createdAt: string;
1112
updatedAt: string;
1213
externalId: string | null;
@@ -22,6 +23,7 @@ export interface UserResponse {
2223
first_name: string | null;
2324
last_name: string | null;
2425
last_sign_in_at: string | null;
26+
locale: string | null;
2527
created_at: string;
2628
updated_at: string;
2729
external_id?: string;

src/user-management/serializers/update-user-options.serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export const serializeUpdateUserOptions = (
1111
password_hash: options.passwordHash,
1212
password_hash_type: options.passwordHashType,
1313
external_id: options.externalId,
14+
locale: options.locale,
1415
metadata: options.metadata,
1516
});

src/user-management/serializers/user.serializer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const deserializeUser = (user: UserResponse): User => ({
99
profilePictureUrl: user.profile_picture_url,
1010
lastName: user.last_name,
1111
lastSignInAt: user.last_sign_in_at,
12+
locale: user.locale,
1213
createdAt: user.created_at,
1314
updatedAt: user.updated_at,
1415
externalId: user.external_id ?? null,

src/user-management/user-management.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('UserManagement', () => {
5656
lastName: 'User',
5757
emailVerified: true,
5858
lastSignInAt: '2023-07-18T02:07:19.911Z',
59+
locale: 'en-US',
5960
});
6061
});
6162
});
@@ -78,6 +79,7 @@ describe('UserManagement', () => {
7879
lastName: 'User',
7980
emailVerified: true,
8081
lastSignInAt: '2023-07-18T02:07:19.911Z',
82+
locale: 'en-US',
8183
externalId,
8284
});
8385
});
@@ -1479,6 +1481,25 @@ describe('UserManagement', () => {
14791481
metadata: {},
14801482
});
14811483
});
1484+
1485+
it('updates user locale', async () => {
1486+
fetchOnce(userFixture);
1487+
1488+
const resp = await workos.userManagement.updateUser({
1489+
userId,
1490+
locale: 'en-US',
1491+
});
1492+
1493+
expect(fetchURL()).toContain(`/user_management/users/${userId}`);
1494+
expect(fetchBody()).toEqual({
1495+
locale: 'en-US',
1496+
});
1497+
1498+
expect(resp).toMatchObject({
1499+
id: userId,
1500+
locale: 'en-US',
1501+
});
1502+
});
14821503
});
14831504

14841505
describe('enrollAuthFactor', () => {

0 commit comments

Comments
 (0)