|
1 | | -import { SdkResponse } from '@descope/core-js-sdk'; |
| 1 | +import { JWTResponse, SdkResponse } from '@descope/core-js-sdk'; |
2 | 2 | import withManagement from '.'; |
3 | 3 | import apiPaths from './paths'; |
4 | 4 | import { UpdateJWTResponse } from './types'; |
@@ -91,4 +91,110 @@ describe('Management JWT', () => { |
91 | 91 | }); |
92 | 92 | }); |
93 | 93 | }); |
| 94 | + |
| 95 | + describe('sign-in', () => { |
| 96 | + it('should send the correct request and receive correct response', async () => { |
| 97 | + const httpResponse = { |
| 98 | + ok: true, |
| 99 | + json: () => mockJWTResponse, |
| 100 | + clone: () => ({ |
| 101 | + json: () => Promise.resolve(mockJWTResponse), |
| 102 | + }), |
| 103 | + status: 200, |
| 104 | + }; |
| 105 | + mockHttpClient.post.mockResolvedValue(httpResponse); |
| 106 | + |
| 107 | + const resp: SdkResponse<JWTResponse> = await management.jwt.signIn('user-id-1', { |
| 108 | + customClaims: { k1: 'v1' }, |
| 109 | + }); |
| 110 | + |
| 111 | + expect(mockHttpClient.post).toHaveBeenCalledWith( |
| 112 | + apiPaths.jwt.signIn, |
| 113 | + { loginId: 'user-id-1', customClaims: { k1: 'v1' } }, |
| 114 | + { token: 'key' }, |
| 115 | + ); |
| 116 | + |
| 117 | + expect(resp).toEqual({ code: 200, data: mockJWTResponse, ok: true, response: httpResponse }); |
| 118 | + }); |
| 119 | + }); |
| 120 | + |
| 121 | + describe('sign-up', () => { |
| 122 | + it('should send the correct request and receive correct response', async () => { |
| 123 | + const httpResponse = { |
| 124 | + ok: true, |
| 125 | + json: () => mockJWTResponse, |
| 126 | + clone: () => ({ |
| 127 | + json: () => Promise.resolve(mockJWTResponse), |
| 128 | + }), |
| 129 | + status: 200, |
| 130 | + }; |
| 131 | + mockHttpClient.post.mockResolvedValue(httpResponse); |
| 132 | + |
| 133 | + const resp: SdkResponse<JWTResponse> = await management.jwt.signUp( |
| 134 | + 'user-id-1', |
| 135 | + { |
| 136 | + email: 'test@example.com', |
| 137 | + name: 'lorem ipsum', |
| 138 | + }, |
| 139 | + { |
| 140 | + customClaims: { k1: 'v1' }, |
| 141 | + }, |
| 142 | + ); |
| 143 | + |
| 144 | + expect(mockHttpClient.post).toHaveBeenCalledWith( |
| 145 | + apiPaths.jwt.signUp, |
| 146 | + { |
| 147 | + loginId: 'user-id-1', |
| 148 | + user: { |
| 149 | + email: 'test@example.com', |
| 150 | + name: 'lorem ipsum', |
| 151 | + }, |
| 152 | + customClaims: { k1: 'v1' }, |
| 153 | + }, |
| 154 | + { token: 'key' }, |
| 155 | + ); |
| 156 | + |
| 157 | + expect(resp).toEqual({ code: 200, data: mockJWTResponse, ok: true, response: httpResponse }); |
| 158 | + }); |
| 159 | + }); |
| 160 | + |
| 161 | + describe('sign-up-or-in', () => { |
| 162 | + it('should send the correct request and receive correct response', async () => { |
| 163 | + const httpResponse = { |
| 164 | + ok: true, |
| 165 | + json: () => mockJWTResponse, |
| 166 | + clone: () => ({ |
| 167 | + json: () => Promise.resolve(mockJWTResponse), |
| 168 | + }), |
| 169 | + status: 200, |
| 170 | + }; |
| 171 | + mockHttpClient.post.mockResolvedValue(httpResponse); |
| 172 | + |
| 173 | + const resp: SdkResponse<JWTResponse> = await management.jwt.signUpOrIn( |
| 174 | + 'user-id-1', |
| 175 | + { |
| 176 | + email: 'test@example.com', |
| 177 | + name: 'lorem ipsum', |
| 178 | + }, |
| 179 | + { |
| 180 | + customClaims: { k1: 'v1' }, |
| 181 | + }, |
| 182 | + ); |
| 183 | + |
| 184 | + expect(mockHttpClient.post).toHaveBeenCalledWith( |
| 185 | + apiPaths.jwt.signUpOrIn, |
| 186 | + { |
| 187 | + loginId: 'user-id-1', |
| 188 | + user: { |
| 189 | + email: 'test@example.com', |
| 190 | + name: 'lorem ipsum', |
| 191 | + }, |
| 192 | + customClaims: { k1: 'v1' }, |
| 193 | + }, |
| 194 | + { token: 'key' }, |
| 195 | + ); |
| 196 | + |
| 197 | + expect(resp).toEqual({ code: 200, data: mockJWTResponse, ok: true, response: httpResponse }); |
| 198 | + }); |
| 199 | + }); |
94 | 200 | }); |
0 commit comments