99 WrongCredentialsError ,
1010 UsernameAlreadyExistsError ,
1111} from "../src/errors/authErrors" ;
12- import { safelyDeleteUser } from "./helpers/createUser" ;
12+ import { getUserCredentials , safelyDeleteUser } from "./helpers/createUser" ;
1313import { NodeFile } from "../src/helpers/file" ;
1414import { FileTooLargeError , UnsupportedFileTypeError } from "../src/errors" ;
1515
@@ -23,33 +23,33 @@ const client = await createClient({
2323 endpoint : process . env . KODADO_URL || "" ,
2424} ) ;
2525
26+ const credentials = getUserCredentials ( {
27+ email : "auth-lib-user@turingpoint.de" ,
28+ password : "Abcd1234!" ,
29+ username : "auth-lib-user" ,
30+ fullName : "Auth Lib User" ,
31+ companyName : "CompanyXYZ" ,
32+ } ) ;
33+
2634beforeAll ( async ( ) => {
27- await safelyDeleteUser ( client , {
28- email : "auth-lib-user@turingpoint.de" ,
29- password : "Abcd1234!" ,
30- username : "auth-lib-user" ,
31- } ) ;
35+ await safelyDeleteUser ( client , credentials ) ;
3236} ) ;
3337
3438describe ( "signUp" , ( ) => {
3539 it ( "Should sign up a new user" , async ( ) => {
3640 const result = await client . auth . signUp ( {
37- email : "auth-lib-user@turingpoint.de" ,
38- password : "Abcd1234!" ,
39- nickname : "auth-lib-user" ,
40- fullName : "Auth Lib User" ,
41- companyName : "CompanyXYZ" ,
41+ ...credentials ,
42+ nickname : credentials . username ,
4243 } ) ;
4344
44- expect ( result ?. username ) . toBe ( "auth-lib-user" ) ;
45+ expect ( result ?. username ) . toBe ( credentials . username ) ;
4546 } ) ;
4647
4748 it ( "Should throw error if email was already taken" , async ( ) => {
4849 try {
4950 await client . auth . signUp ( {
50- email : "auth-lib-user@turingpoint.de" ,
51- password : "Abcd1234!" ,
52- nickname : "auth-lib-user" ,
51+ ...credentials ,
52+ nickname : credentials . username ,
5353 } ) ;
5454 } catch ( e ) {
5555 expect ( e ) . toBeInstanceOf ( UsernameAlreadyExistsError ) ;
@@ -59,20 +59,17 @@ describe("signUp", () => {
5959
6060describe ( "signIn" , ( ) => {
6161 it ( "Should sign the user in" , async ( ) => {
62- const user = await client . auth . signIn ( {
63- email : "auth-lib-user@turingpoint.de" ,
64- password : "Abcd1234!" ,
65- } ) ;
62+ const user = await client . auth . signIn ( credentials ) ;
6663
6764 if ( ! user ) {
6865 expect ( false ) . toBe ( true ) ;
6966 return ;
7067 }
7168
72- expect ( user . email ) . toBe ( "auth-lib-user@turingpoint.de" ) ;
73- expect ( user . nickname ) . toBe ( "auth-lib-user" ) ;
74- expect ( user . fullName ) . toBe ( "Auth Lib User" ) ;
75- expect ( user . companyName ) . toBe ( "CompanyXYZ" ) ;
69+ expect ( user . email ) . toBe ( credentials . email ) ;
70+ expect ( user . nickname ) . toBe ( credentials . username ) ;
71+ expect ( user . fullName ) . toBe ( credentials . fullName ) ;
72+ expect ( user . companyName ) . toBe ( credentials . companyName ) ;
7673 expect ( user ) . toHaveProperty ( "keys" ) ;
7774 expect ( user ) . toHaveProperty ( "keys.encryptionPublicKey" ) ;
7875 expect ( user ) . toHaveProperty ( "keys.encryptionSecretKey" ) ;
@@ -86,8 +83,8 @@ describe("signIn", () => {
8683 it ( "Should throw error if user is not found" , async ( ) => {
8784 try {
8885 await client . auth . signIn ( {
86+ ...credentials ,
8987 email : "notexisting@test.de" ,
90- password : "Abcd1234!" ,
9188 } ) ;
9289 expect ( false ) . toBe ( true ) ;
9390 } catch ( e ) {
@@ -97,10 +94,7 @@ describe("signIn", () => {
9794
9895 it ( "Should throw an error if password is wrong" , async ( ) => {
9996 try {
100- await client . auth . signIn ( {
101- email : "auth-lib-user@turingpoint.de" ,
102- password : "wrongpw" ,
103- } ) ;
97+ await client . auth . signIn ( { ...credentials , password : "wrongpw" } ) ;
10498 expect ( false ) . toBe ( true ) ;
10599 } catch ( e ) {
106100 expect ( e ) . toBeInstanceOf ( WrongCredentialsError ) ;
@@ -109,14 +103,8 @@ describe("signIn", () => {
109103
110104 it ( "Should throw error if user is already signed in." , async ( ) => {
111105 try {
112- await client . auth . signIn ( {
113- email : "auth-lib-user@turingpoint.de" ,
114- password : "Abcd1234!" ,
115- } ) ;
116- await client . auth . signIn ( {
117- email : "auth-lib-user@turingpoint.de" ,
118- password : "Abcd1234!" ,
119- } ) ;
106+ await client . auth . signIn ( credentials ) ;
107+ await client . auth . signIn ( credentials ) ;
120108 expect ( false ) . toBe ( true ) ;
121109 } catch ( e ) {
122110 expect ( e ) . toBeInstanceOf ( AlreadySignedInError ) ;
@@ -127,10 +115,7 @@ describe("signIn", () => {
127115
128116describe ( "updateProfile" , ( ) => {
129117 it ( "Should update the profile" , async ( ) => {
130- await client . auth . signIn ( {
131- email : "auth-lib-user@turingpoint.de" ,
132- password : "Abcd1234!" ,
133- } ) ;
118+ await client . auth . signIn ( credentials ) ;
134119
135120 await client . auth . updateProfile ( {
136121 fullName : "updated fullName" ,
@@ -139,10 +124,7 @@ describe("updateProfile", () => {
139124 } ) ;
140125
141126 client . auth . signOut ( ) ;
142- const session = await client . auth . signIn ( {
143- email : "auth-lib-user@turingpoint.de" ,
144- password : "Abcd1234!" ,
145- } ) ;
127+ const session = await client . auth . signIn ( credentials ) ;
146128
147129 if ( ! session ) {
148130 expect ( false ) . toBe ( true ) ;
@@ -159,10 +141,7 @@ describe("updateProfile", () => {
159141
160142describe ( "uploadProfileImage" , ( ) => {
161143 it ( "Should fail uploading large images" , async ( ) => {
162- await client . auth . signIn ( {
163- email : "auth-lib-user@turingpoint.de" ,
164- password : "Abcd1234!" ,
165- } ) ;
144+ await client . auth . signIn ( credentials ) ;
166145
167146 const file : NodeFile = {
168147 buffer : fs . readFileSync (
@@ -179,10 +158,7 @@ describe("uploadProfileImage", () => {
179158 } ) ;
180159
181160 it ( "Should fail uploading non image files" , async ( ) => {
182- await client . auth . signIn ( {
183- email : "auth-lib-user@turingpoint.de" ,
184- password : "Abcd1234!" ,
185- } ) ;
161+ await client . auth . signIn ( credentials ) ;
186162
187163 const file : NodeFile = {
188164 buffer : fs . readFileSync (
@@ -199,10 +175,7 @@ describe("uploadProfileImage", () => {
199175 } ) ;
200176
201177 it ( "Should upload a profile image" , async ( ) => {
202- await client . auth . signIn ( {
203- email : "auth-lib-user@turingpoint.de" ,
204- password : "Abcd1234!" ,
205- } ) ;
178+ await client . auth . signIn ( credentials ) ;
206179
207180 const file : NodeFile = {
208181 buffer : fs . readFileSync (
@@ -215,10 +188,7 @@ describe("uploadProfileImage", () => {
215188
216189 client . auth . signOut ( ) ;
217190
218- const session = await client . auth . signIn ( {
219- email : "auth-lib-user@turingpoint.de" ,
220- password : "Abcd1234!" ,
221- } ) ;
191+ const session = await client . auth . signIn ( credentials ) ;
222192
223193 if ( session === "MFA_REQUIRED" ) {
224194 expect ( false ) . toBe ( true ) ;
@@ -236,10 +206,7 @@ describe("uploadProfileImage", () => {
236206 } ) ;
237207
238208 it ( "Uploaded image should be the same as accessable via imageUrl" , async ( ) => {
239- const session = await client . auth . signIn ( {
240- email : "auth-lib-user@turingpoint.de" ,
241- password : "Abcd1234!" ,
242- } ) ;
209+ const session = await client . auth . signIn ( credentials ) ;
243210
244211 if ( session === "MFA_REQUIRED" ) {
245212 expect ( false ) . toBe ( true ) ;
@@ -268,18 +235,12 @@ describe("uploadProfileImage", () => {
268235
269236describe ( "deleteUser" , ( ) => {
270237 it ( "Should delete the current user" , async ( ) => {
271- await client . auth . signIn ( {
272- email : "auth-lib-user@turingpoint.de" ,
273- password : "Abcd1234!" ,
274- } ) ;
238+ await client . auth . signIn ( credentials ) ;
275239
276240 await client . auth . deleteUser ( ) ;
277241
278242 try {
279- await client . auth . signIn ( {
280- email : "auth-lib-user@turingpoint.de" ,
281- password : "Abcd1234!" ,
282- } ) ;
243+ await client . auth . signIn ( credentials ) ;
283244 expect ( false ) . toBe ( true ) ;
284245 } catch ( e ) {
285246 if ( e instanceof WrongCredentialsError ) {
0 commit comments