@@ -4,6 +4,8 @@ import { API_FULL_URL, API_KEY } from '../../../lib/constants';
4
4
import { TokenModule } from '../../../../src/modules/token' ;
5
5
import { UsersModule } from '../../../../src/modules/users' ;
6
6
import { UtilsModule } from '../../../../src/modules/utils' ;
7
+ import { get } from '../../../../src/utils/rest' ;
8
+ import { createApiKeyMissingError } from '../../../../src/core/sdk-exceptions' ;
7
9
8
10
test ( 'Initialize `MagicAdminSDK`' , ( ) => {
9
11
const magic = new Magic ( API_KEY ) ;
@@ -33,3 +35,62 @@ test('Strips trailing slash(es) from custom endpoint argument', () => {
33
35
expect ( magicB . apiBaseUrl ) . toBe ( 'https://example.com' ) ;
34
36
expect ( magicC . apiBaseUrl ) . toBe ( 'https://example.com' ) ;
35
37
} ) ;
38
+
39
+ test ( 'Initialize `MagicAdminSDK` using static init and empty options' , async ( ) => {
40
+ const successRes = Promise . resolve ( {
41
+ client_id : 'foo' ,
42
+ app_scope : 'GLOBAL' ,
43
+ } ) ;
44
+ ( get as any ) = jest . fn ( ) . mockImplementation ( ( ) => successRes ) ;
45
+
46
+ const magic = await Magic . init ( API_KEY , { } ) ;
47
+
48
+ expect ( magic . secretApiKey ) . toBe ( API_KEY ) ;
49
+ expect ( magic . apiBaseUrl ) . toBe ( API_FULL_URL ) ;
50
+ expect ( magic . token instanceof TokenModule ) . toBe ( true ) ;
51
+ expect ( magic . users instanceof UsersModule ) . toBe ( true ) ;
52
+ } ) ;
53
+
54
+ test ( 'Initialize `MagicAdminSDK` using static init and undefined options' , async ( ) => {
55
+ const successRes = Promise . resolve ( {
56
+ client_id : 'foo' ,
57
+ app_scope : 'GLOBAL' ,
58
+ } ) ;
59
+ ( get as any ) = jest . fn ( ) . mockImplementation ( ( ) => successRes ) ;
60
+
61
+ const magic = await Magic . init ( API_KEY ) ;
62
+
63
+ expect ( magic . secretApiKey ) . toBe ( API_KEY ) ;
64
+ expect ( magic . apiBaseUrl ) . toBe ( API_FULL_URL ) ;
65
+ expect ( magic . token instanceof TokenModule ) . toBe ( true ) ;
66
+ expect ( magic . users instanceof UsersModule ) . toBe ( true ) ;
67
+ } ) ;
68
+
69
+ test ( 'Initialize `MagicAdminSDK` using static init and client ID' , async ( ) => {
70
+ const magic = await Magic . init ( API_KEY , { clientId : '1234' } ) ;
71
+
72
+ expect ( magic . secretApiKey ) . toBe ( API_KEY ) ;
73
+ expect ( magic . apiBaseUrl ) . toBe ( API_FULL_URL ) ;
74
+ expect ( magic . token instanceof TokenModule ) . toBe ( true ) ;
75
+ expect ( magic . users instanceof UsersModule ) . toBe ( true ) ;
76
+ } ) ;
77
+
78
+ test ( 'Initialize `MagicAdminSDK` using static init and endpoint' , async ( ) => {
79
+ const successRes = Promise . resolve ( {
80
+ client_id : 'foo' ,
81
+ app_scope : 'GLOBAL' ,
82
+ } ) ;
83
+ ( get as any ) = jest . fn ( ) . mockImplementation ( ( ) => successRes ) ;
84
+
85
+ const magic = await Magic . init ( API_KEY , { endpoint : 'https://example.com' } ) ;
86
+
87
+ expect ( magic . secretApiKey ) . toBe ( API_KEY ) ;
88
+ expect ( magic . apiBaseUrl ) . toBe ( 'https://example.com' ) ;
89
+ expect ( magic . token instanceof TokenModule ) . toBe ( true ) ;
90
+ expect ( magic . users instanceof UsersModule ) . toBe ( true ) ;
91
+ } ) ;
92
+
93
+ test ( 'Initialize `MagicAdminSDK` missing API Key' , async ( ) => {
94
+ const expectedError = createApiKeyMissingError ( ) ;
95
+ expect ( Magic . init ( null , { clientId : '1234' } ) ) . rejects . toThrow ( expectedError ) ;
96
+ } ) ;
0 commit comments