-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8e4848
commit 93cdd83
Showing
16 changed files
with
382 additions
and
33 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
61 changes: 61 additions & 0 deletions
61
free-sample-product-service/src/connector/post-deploy.test.ts
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,61 @@ | ||
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(), | ||
assertString: jest.fn(), | ||
})); | ||
|
||
jest | ||
.spyOn(actions, 'createChannelAndInventory') | ||
.mockReturnValue(Promise.resolve()); | ||
|
||
jest | ||
.spyOn(actions, 'createCartUpdateExtension') | ||
.mockReturnValue(Promise.resolve()); | ||
|
||
describe('run functions', () => { | ||
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, 'createChannelAndInventory') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
jest | ||
.spyOn(actions, 'createCartUpdateExtension') | ||
.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, 'createChannelAndInventory') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
jest | ||
.spyOn(actions, 'createCartUpdateExtension') | ||
.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
59 changes: 59 additions & 0 deletions
59
free-sample-product-service/src/connector/pre-undeploy.test.ts
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,59 @@ | ||
import { assertError } from '../utils/assert.utils'; | ||
import * as preUndeploy from './pre-undeploy'; | ||
import * as actions from './actions'; | ||
|
||
jest.mock('../utils/assert.utils', () => ({ | ||
assertError: jest.fn(), | ||
assertString: jest.fn(), | ||
})); | ||
|
||
jest | ||
.spyOn(actions, 'deleteChannelAndInventory') | ||
.mockReturnValue(Promise.resolve()); | ||
|
||
jest | ||
.spyOn(actions, 'deleteCartUpdateExtension') | ||
.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 = `Pre-undeploy failed: ${mockError.message}`; | ||
jest | ||
.spyOn(actions, 'deleteChannelAndInventory') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
jest | ||
.spyOn(actions, 'deleteCartUpdateExtension') | ||
.mockRejectedValueOnce(mockError); | ||
const writeSpy = jest.spyOn(process.stderr, 'write'); | ||
|
||
await preUndeploy.run(); | ||
|
||
expect(assertError).toHaveBeenCalledWith(mockError); | ||
expect(writeSpy).toHaveBeenCalledWith(mockErrorMessage); | ||
}); | ||
|
||
it('should not throw an error when preUndeploy succeeds', async () => { | ||
const mockError = new Error('Test error'); | ||
jest | ||
.spyOn(preUndeploy, 'run') | ||
.mockImplementationOnce(() => Promise.resolve()); | ||
const writeSpy = jest.spyOn(process.stderr, 'write'); | ||
await preUndeploy.run(); | ||
jest | ||
.spyOn(actions, 'deleteChannelAndInventory') | ||
.mockRejectedValueOnce(mockError); | ||
|
||
jest | ||
.spyOn(actions, 'deleteCartUpdateExtension') | ||
.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
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
39 changes: 39 additions & 0 deletions
39
new-category-cleanup-job-app/src/utils/config.utils.test.ts
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,39 @@ | ||
import CustomError from '../errors/custom.error'; | ||
import { readConfiguration } from './config.utils'; | ||
import * as validatorHelper from '../validators/helpers.validators'; | ||
|
||
// Mock .env | ||
const mockEnv = { | ||
CTP_CLIENT_ID: 'mockClientId', | ||
CTP_CLIENT_SECRET: 'mockClientSecret', | ||
CTP_PROJECT_KEY: 'mockProjectKey', | ||
CTP_REGION: 'mockRegion', | ||
NEW_CATEGORY_KEY: 'mockCategoryKey', | ||
}; | ||
|
||
describe('readConfiguration', () => { | ||
it('should return the correct configuration when env variables are valid', () => { | ||
process.env = mockEnv | ||
const expectedConfig = { | ||
clientId: 'mockClientId', | ||
clientSecret: 'mockClientSecret', | ||
projectKey: 'mockProjectKey', | ||
region: 'mockRegion', | ||
categoryKey: 'mockCategoryKey', | ||
}; | ||
|
||
// Mock the validation function to return an empty array | ||
jest.spyOn(validatorHelper, 'getValidateMessages').mockReturnValue([]); | ||
|
||
const config = readConfiguration(); | ||
expect(config).toEqual(expectedConfig); | ||
}); | ||
|
||
it('should throw a CustomError when env variables are invalid', () => { | ||
process.env = mockEnv | ||
// Mock the validation function to return validation errors | ||
jest.spyOn(validatorHelper, 'getValidateMessages').mockReturnValue(['Invalid variable: CTP_CLIENT_ID']); | ||
|
||
expect(() => {readConfiguration();}).toThrow(CustomError); | ||
}); | ||
}); |
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,7 @@ | ||
import { logger } from "./logger.utils" | ||
|
||
describe("logger object", () => { | ||
it("should not throw an error when logger object", () => { | ||
expect(typeof logger).toEqual('object'); | ||
}); | ||
}); |
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,50 @@ | ||
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(), | ||
assertString: jest.fn(), | ||
})); | ||
|
||
jest | ||
.spyOn(actions, 'createProductPublishedSubscription') | ||
.mockReturnValue(Promise.resolve()); | ||
|
||
describe('run functions', () => { | ||
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(); | ||
}); | ||
}); |
Oops, something went wrong.