-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(unit): add tests for createStrapiSDK function
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createStrapiSDK, StrapiSDKInitializationError, StrapiSDKValidationError } from '../../src'; | ||
import { StrapiSDK } from '../../src/sdk'; | ||
|
||
import type { StrapiSDKConfig } from '../../src/sdk'; | ||
|
||
describe('createStrapiSDK', () => { | ||
it('should create an SDK instance with valid configuration', () => { | ||
// Arrange | ||
const config = { baseURL: 'https://api.example.com' } satisfies StrapiSDKConfig; | ||
|
||
// Act | ||
const sdkInstance = createStrapiSDK(config); | ||
|
||
// Assert | ||
expect(sdkInstance).toBeInstanceOf(StrapiSDK); | ||
expect(sdkInstance).toHaveProperty('baseURL', config.baseURL); | ||
}); | ||
|
||
it('should throw an error for an invalid baseURL', () => { | ||
// Arrange | ||
const config = { baseURL: 'invalid-url' } satisfies StrapiSDKConfig; | ||
|
||
// Act & Assert | ||
expect(() => createStrapiSDK(config)).toThrow(StrapiSDKInitializationError); | ||
}); | ||
|
||
it('should throw an error if auth configuration is invalid', () => { | ||
// Arrange | ||
const config = { | ||
baseURL: 'https://api.example.com', | ||
auth: { | ||
strategy: 'api-token', | ||
options: { token: '' }, // Invalid token | ||
}, | ||
} satisfies StrapiSDKConfig; | ||
|
||
// Act & Assert | ||
expect(() => createStrapiSDK(config)).toThrow(StrapiSDKValidationError); | ||
}); | ||
}); |