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
51 changes: 51 additions & 0 deletions lib/management/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,50 @@ describe('Management User', () => {
});
});

it('should send locale via the positional arguments overload', async () => {
const httpResponse = {
ok: true,
json: () => mockMgmtUserResponse,
clone: () => ({
json: () => Promise.resolve(mockMgmtUserResponse),
}),
status: 200,
};
mockHttpClient.post.mockResolvedValue(httpResponse);

await management.user.invite(
'loginId',
'a@b.c',
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
'en-US',
);

expect(mockHttpClient.post).toHaveBeenCalledWith(
apiPaths.user.create,
expect.objectContaining({
loginId: 'loginId',
email: 'a@b.c',
locale: 'en-US',
invite: true,
}),
);
});

it('should send the correct request and receive correct response with options argument', async () => {
const httpResponse = {
ok: true,
Expand All @@ -326,6 +370,7 @@ describe('Management User', () => {
inviteUrl: 'https://invite.me',
sendMail: true,
templateOptions: { k1: 'v1' },
locale: 'en-US',
});
Comment thread
asafshen marked this conversation as resolved.

expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.user.create, {
Expand All @@ -337,6 +382,7 @@ describe('Management User', () => {
inviteUrl: 'https://invite.me',
sendMail: true,
templateOptions: { k1: 'v1' },
locale: 'en-US',
});

expect(resp).toEqual({
Expand Down Expand Up @@ -407,6 +453,10 @@ describe('Management User', () => {
],
'https://invite.me',
true,
undefined,
undefined,
undefined,
'fr-FR',
);

expect(mockHttpClient.post).toHaveBeenCalledWith(apiPaths.user.createBatch, {
Expand Down Expand Up @@ -437,6 +487,7 @@ describe('Management User', () => {
invite: true,
inviteUrl: 'https://invite.me',
sendMail: true,
locale: 'fr-FR',
});

expect(resp).toEqual({
Expand Down
6 changes: 6 additions & 0 deletions lib/management/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ const withUser = (httpClient: HttpClient) => {
sendSMS?: boolean; // send invite via text message, default is according to project settings
templateOptions?: TemplateOptions;
templateId?: string;
locale?: string; // locale for the invite message
},
): Promise<SdkResponse<UserResponse>>;
function invite(
Expand All @@ -251,6 +252,7 @@ const withUser = (httpClient: HttpClient) => {
familyName?: string,
additionalLoginIds?: string[],
templateId?: string,
locale?: string, // locale for the invite message
): Promise<SdkResponse<UserResponse>>;

function invite(
Expand All @@ -272,6 +274,7 @@ const withUser = (httpClient: HttpClient) => {
familyName?: string,
additionalLoginIds?: string[],
templateId?: string,
locale?: string, // locale for the invite message
): Promise<SdkResponse<UserResponse>> {
// We support both the old and new parameters forms of invite user
// 1. The new form - invite(loginIdOrUserId, { email, phone, ... }})
Expand All @@ -298,6 +301,7 @@ const withUser = (httpClient: HttpClient) => {
sendSMS,
additionalLoginIds,
templateId,
locale,
}
: {
loginId: loginIdOrUserId,
Expand Down Expand Up @@ -511,6 +515,7 @@ const withUser = (httpClient: HttpClient) => {
sendSMS?: boolean, // send invite via text message, default is according to project settings
templateOptions?: TemplateOptions,
templateId?: string,
locale?: string, // locale for the invite message
): Promise<SdkResponse<CreateOrInviteBatchResponse>> =>
transformResponse<CreateOrInviteBatchResponse, CreateOrInviteBatchResponse>(
httpClient.post(apiPaths.user.createBatch, {
Expand All @@ -521,6 +526,7 @@ const withUser = (httpClient: HttpClient) => {
sendSMS,
templateOptions,
templateId,
locale,
}),
(data) => data,
),
Expand Down
Loading