Skip to content

Commit

Permalink
synthetics mobile command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dd-spells committed Mar 19, 2024
1 parent 00d73f6 commit a43f07d
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 207 deletions.
16 changes: 16 additions & 0 deletions src/commands/synthetics/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
MOBILE_PRESIGNED_UPLOAD_PARTS,
mockSearchResponse,
mockTestTriggerResponse,
APP_UPLOAD_POLL_RESULTS,
} from './fixtures'

describe('dd-api', () => {
Expand Down Expand Up @@ -280,6 +281,21 @@ describe('dd-api', () => {
spy.mockRestore()
})

test('should poll for app upload validation', async () => {
const mockRequest = jest.fn()
const spy = jest.spyOn(axios, 'create').mockImplementation((() => () => ({data: APP_UPLOAD_POLL_RESULTS})) as any)
const api = apiConstructor(apiConfiguration)
const {pollMobileApplicationUploadResponse} = api

const jobId = 'jobId'

const appUploadResult = await pollMobileApplicationUploadResponse(jobId)

expect(mockRequest).toHaveBeenCalled()
expect(appUploadResult).toEqual(APP_UPLOAD_POLL_RESULTS)
spy.mockRestore()
})

test('should perform search with expected parameters', async () => {
const requestMock = jest.fn(() => ({status: 200, data: {tests: []}}))
const spy = jest.spyOn(axios, 'create').mockImplementation((() => requestMock) as any)
Expand Down
55 changes: 44 additions & 11 deletions src/commands/synthetics/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ExecutionRule,
Location,
MainReporter,
MobileApplicationVersion,
MultiStep,
MultiStepsServerResult,
MobileApplicationUploadPart,
Expand All @@ -33,7 +32,12 @@ import {
Trigger,
UploadApplicationCommandConfig,
User,
MobileAppUploadResult,
MobileApplicationUploadPartResponse,
TestWithOverride,
TriggerConfig,
} from '../interfaces'
import { AppUploadReporter } from '../reporters/appUpload'
import {createInitialSummary} from '../utils/public'

const mockUser: User = {
Expand Down Expand Up @@ -569,16 +573,18 @@ export const getTestPayload = (override?: Partial<TestPayload>) => ({
...override,
})

export const getMobileVersion = (override?: Partial<MobileApplicationVersion>) => ({
id: '123-abc-456',
application_id: '789-dfg-987',
file_name: 'bla.',
original_file_name: 'test.apk',
is_latest: true,
version_name: 'test version',
created_at: '22-09-2022',
...override,
})
export const getTestAndConfigOverride = (appId: string): TestWithOverride => {
const testWithOverride = {test: getMobileTest(), overriddenConfig: getTestPayload()}
testWithOverride.test.options.mobileApplication!.applicationId = appId

return testWithOverride
}

export const getTriggerConfig = (appPath?: string, appVersion?: string): TriggerConfig => {
const config = appPath ? {mobileApplicationVersionFilePath: appPath} : {mobileApplicationVersion: appVersion}

return {id: 'abc', config}
}

export const uploadCommandConfig: UploadApplicationCommandConfig = {
apiKey: 'foo',
Expand Down Expand Up @@ -608,3 +614,30 @@ export const MOBILE_PRESIGNED_UPLOAD_PARTS: MobileApplicationUploadPart[] = [
{partNumber: 1, md5: 'md5', blob: Buffer.from('content1')},
{partNumber: 2, md5: 'md5', blob: Buffer.from('content2')},
]

export const APP_UPLOAD_POLL_RESULTS: MobileAppUploadResult = {
status: 'complete',
is_valid: true,
}

export const APP_UPLOAD_SIZE_AND_PARTS = {
appSize: 1000,
parts: MOBILE_PRESIGNED_UPLOAD_PARTS,
}

export const APP_UPLOAD_PART_RESPONSES: MobileApplicationUploadPartResponse[] = MOBILE_PRESIGNED_UPLOAD_PARTS.map(
(partNumber) => ({
PartNumber: Number(partNumber),
ETag: 'etag',
})
)

export const getMockAppUploadReporter = (): AppUploadReporter => {
const reporter: AppUploadReporter = new AppUploadReporter({} as any)
reporter.start = jest.fn()
reporter.renderProgress = jest.fn()
reporter.reportSuccess = jest.fn()
reporter.reportFailure = jest.fn()

return reporter
}
Loading

0 comments on commit a43f07d

Please sign in to comment.