-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from composable-com/dev
dev to master
- Loading branch information
Showing
25 changed files
with
1,349 additions
and
249 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ coverage | |
.DS_Store | ||
.vscode | ||
build/ | ||
.env | ||
.env | ||
.idea |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"semi": false, | ||
"singleQuote": true, | ||
"parser": "typescript", | ||
"printWidth": 80, | ||
|
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,36 @@ | ||
import { createClient } from './build.client'; | ||
import { ClientBuilder } from '@commercetools/sdk-client-v2'; | ||
|
||
jest.mock('@commercetools/sdk-client-v2', () => ({ | ||
ClientBuilder: jest.fn().mockImplementation(() => ({ | ||
withProjectKey: jest.fn().mockReturnThis(), | ||
withClientCredentialsFlow: jest.fn().mockReturnThis(), | ||
withHttpMiddleware: jest.fn().mockReturnThis(), | ||
build: jest.fn(), | ||
})), | ||
})); | ||
|
||
jest.mock('../middleware/auth.middleware', () => ({ | ||
authMiddlewareOptions: jest.fn(), | ||
})); | ||
|
||
jest.mock('../middleware/http.middleware', () => ({ | ||
httpMiddlewareOptions: jest.fn(), | ||
})); | ||
|
||
jest.mock('../utils/config.utils', () => ({ | ||
readConfiguration: jest.fn().mockReturnValue({ | ||
projectKey: 'test-project-key', | ||
}), | ||
})); | ||
|
||
describe('createClient function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should create a new Client with the correct configuration', () => { | ||
createClient(); | ||
expect(ClientBuilder).toHaveBeenCalled(); | ||
}); | ||
}); |
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,23 @@ | ||
import { createApiRoot } from './create.client'; | ||
|
||
jest.mock('../utils/config.utils', () => ({ | ||
readConfiguration: jest.fn().mockReturnValue({ | ||
projectKey: 'test-project-key', | ||
clientId: 'test-client-id', | ||
clientSecret: 'test-client-secret', | ||
scope: 'test-scope', | ||
region: 'test-region' | ||
}), | ||
})); | ||
|
||
describe('createApiRoot function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should create an API root with the correct project key', () => { | ||
const apiRoot = createApiRoot(); | ||
|
||
expect(apiRoot.apiClients).toBeDefined(); | ||
}); | ||
}); |
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,57 @@ | ||
import { assertError } from '../utils/assert.utils'; | ||
import * as postDeploy from './post-deploy'; | ||
import * as actions from './actions'; | ||
|
||
jest.mock('../utils/assert.utils', () => ({ | ||
assertError: jest.fn(), | ||
})); | ||
|
||
jest.mock('../utils/config.utils', () => ({ | ||
readConfiguration: jest.fn().mockReturnValue({ | ||
projectKey: 'test-project-key', | ||
clientId: 'test-client-id', | ||
clientSecret: 'test-client-secret', | ||
scope: 'test-scope', | ||
region: 'test-region' | ||
}), | ||
})); | ||
|
||
jest | ||
.spyOn(actions, 'createProductPublishedSubscription') | ||
.mockReturnValue(Promise.resolve()); | ||
|
||
describe('run function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call postDeploy and handle errors gracefully', async () => { | ||
const mockError = new Error('Test error'); | ||
const mockErrorMessage = `Post-deploy failed: ${mockError.message}`; | ||
jest | ||
.spyOn(actions, 'createProductPublishedSubscription') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
const writeSpy = jest.spyOn(process.stderr, 'write'); | ||
|
||
await postDeploy.run(); | ||
|
||
expect(assertError).toHaveBeenCalledWith(mockError); | ||
expect(writeSpy).toHaveBeenCalledWith(mockErrorMessage); | ||
}); | ||
|
||
it('should not throw an error when postDeploy succeeds', async () => { | ||
const mockError = new Error('Test error'); | ||
jest | ||
.spyOn(postDeploy, 'run') | ||
.mockImplementationOnce(() => Promise.resolve()); | ||
const writeSpy = jest.spyOn(process.stderr, 'write'); | ||
await postDeploy.run(); | ||
jest | ||
.spyOn(actions, 'createProductPublishedSubscription') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
expect(assertError).not.toHaveBeenCalled(); | ||
expect(writeSpy).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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.