-
Notifications
You must be signed in to change notification settings - Fork 55
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
Showing
5 changed files
with
132 additions
and
25 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
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
86 changes: 86 additions & 0 deletions
86
src/commands/synthetics/__tests__/reporters/appUpload.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,86 @@ | ||
import {BaseContext} from 'clipanion/lib/advanced' | ||
|
||
import { AppUploadDetails } from '../../interfaces' | ||
import { AppUploadReporter } from '../../reporters/appUpload' | ||
|
||
describe('AppUploadReporter', () => { | ||
let reporter: AppUploadReporter | ||
|
||
beforeEach(() => { | ||
const writeMock = jest.fn() | ||
const mockContext: unknown = { | ||
stdout: {write: writeMock}, | ||
} | ||
reporter = new AppUploadReporter(mockContext as BaseContext) | ||
|
||
}) | ||
|
||
afterEach(() => { | ||
// Clean up any mocks | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
describe('start', () => { | ||
test('should write the correct output', () => { | ||
const appsToUpload: AppUploadDetails[] = [ | ||
{ | ||
versionName: '1.0.0', | ||
appId: '123', | ||
appPath: '/path/to/app', | ||
}, | ||
{ | ||
versionName: '2.0.0', | ||
appId: '456', | ||
appPath: '/path/to/another/app', | ||
}, | ||
] | ||
|
||
reporter.start(appsToUpload) | ||
|
||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('2 mobile application(s) to upload:') | ||
) | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('Version 1.0.0 - Application ID 123 - Local Path /path/to/app') | ||
) | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('Version 2.0.0 - Application ID 456 - Local Path /path/to/another/app') | ||
) | ||
}) | ||
}) | ||
|
||
describe('reportSuccess', () => { | ||
test('should write the correct output', () => { | ||
reporter.reportSuccess() | ||
|
||
// Assert that the correct output is written to stdout | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('Uploaded applications in') | ||
) | ||
}) | ||
}) | ||
|
||
describe('reportFailure', () => { | ||
test('should write the correct output', () => { | ||
const error = new Error('Failed to upload') | ||
const failedApp: AppUploadDetails = { | ||
versionName: '1.0.0', | ||
appId: '123', | ||
appPath: '/path/to/app', | ||
} | ||
|
||
reporter.reportFailure(error, failedApp) | ||
|
||
// Assert that the correct output is written to stdout | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('Failed to upload application:') | ||
) | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining('Version 1.0.0 - Application ID 123 - Local Path /path/to/app') | ||
) | ||
expect(reporter['context'].stdout.write).toHaveBeenCalledWith( | ||
expect.stringContaining(error.message) | ||
) | ||
}) | ||
}) | ||
}) |
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