-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tenant get/set settings (#334)
added password tenant get/set settings added to readme added tests
- Loading branch information
Showing
10 changed files
with
343 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { SdkResponse } from '@descope/core-js-sdk'; | ||
import withManagement from '.'; | ||
import apiPaths from './paths'; | ||
import { PasswordSettings } from './types'; | ||
import { mockCoreSdk, mockHttpClient } from './testutils'; | ||
|
||
const management = withManagement(mockCoreSdk, 'key'); | ||
|
||
const mockPasswordSettings: PasswordSettings = { | ||
enabled: true, | ||
minLength: 8, | ||
expiration: true, | ||
expirationWeeks: 4, | ||
lock: true, | ||
lockAttempts: 5, | ||
reuse: true, | ||
reuseAmount: 6, | ||
lowercase: true, | ||
uppercase: false, | ||
number: true, | ||
nonAlphaNumeric: false, | ||
}; | ||
|
||
describe('Management Password', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
mockHttpClient.reset(); | ||
}); | ||
|
||
describe('getSettings', () => { | ||
it('should send the correct request and receive correct response', async () => { | ||
const httpResponse = { | ||
ok: true, | ||
json: () => mockPasswordSettings, | ||
clone: () => ({ | ||
json: () => Promise.resolve(mockPasswordSettings), | ||
}), | ||
status: 200, | ||
}; | ||
mockHttpClient.get.mockResolvedValue(httpResponse); | ||
|
||
const resp: SdkResponse<PasswordSettings> = await management.password.getSettings('test'); | ||
|
||
expect(mockHttpClient.get).toHaveBeenCalledWith(apiPaths.password.settings, { | ||
queryParams: { tenantId: 'test' }, | ||
token: 'key', | ||
}); | ||
|
||
expect(resp).toEqual({ | ||
code: 200, | ||
data: mockPasswordSettings, | ||
ok: true, | ||
response: httpResponse, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('configureSettings', () => { | ||
it('should send the correct request and receive correct response', async () => { | ||
const httpResponse = { | ||
ok: true, | ||
json: () => {}, | ||
clone: () => ({ | ||
json: () => Promise.resolve(), | ||
}), | ||
status: 200, | ||
}; | ||
mockHttpClient.post.mockResolvedValue(httpResponse); | ||
|
||
const resp: SdkResponse<never> = await management.password.configureSettings( | ||
'test', | ||
mockPasswordSettings, | ||
); | ||
|
||
expect(mockHttpClient.post).toHaveBeenCalledWith( | ||
apiPaths.password.settings, | ||
{ ...mockPasswordSettings, tenantId: 'test' }, | ||
{ | ||
token: 'key', | ||
}, | ||
); | ||
|
||
expect(resp).toEqual({ | ||
code: 200, | ||
data: undefined, | ||
ok: true, | ||
response: httpResponse, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SdkResponse, transformResponse } from '@descope/core-js-sdk'; | ||
import { CoreSdk } from '../types'; | ||
import apiPaths from './paths'; | ||
import { PasswordSettings } from './types'; | ||
|
||
const withPassword = (sdk: CoreSdk, managementKey?: string) => ({ | ||
getSettings: (tenantId: string): Promise<SdkResponse<PasswordSettings>> => | ||
transformResponse<PasswordSettings, PasswordSettings>( | ||
sdk.httpClient.get(apiPaths.password.settings, { | ||
queryParams: { tenantId }, | ||
token: managementKey, | ||
}), | ||
(data) => data, | ||
), | ||
configureSettings: (tenantId: string, settings: PasswordSettings): Promise<SdkResponse<never>> => | ||
transformResponse( | ||
sdk.httpClient.post( | ||
apiPaths.password.settings, | ||
{ ...settings, tenantId }, | ||
{ | ||
token: managementKey, | ||
}, | ||
), | ||
), | ||
}); | ||
|
||
export default withPassword; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.