diff --git a/src/lib/httpClient.ts b/src/lib/httpClient.ts index 5d43708..bb125b3 100644 --- a/src/lib/httpClient.ts +++ b/src/lib/httpClient.ts @@ -375,7 +375,26 @@ export default class httpClient { }, ctx.log) } - processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) { + processSnapshotCaps(ctx: Context, snapshot: ProcessedSnapshot, snapshotUuid: string, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) { + const requestData: any = { + name: snapshot.name, + url: snapshot.url, + snapshotUuid: snapshotUuid, + variantCount: variantCount, + test: { + type: ctx.testType, + source: 'cli' + }, + doRemoteDiscovery: snapshot.options.doRemoteDiscovery, + discoveryErrors: discoveryErrors, + sync: sync + } + if (approvalThreshold !== undefined) { + requestData.approvalThreshold = approvalThreshold; + } + if (rejectionThreshold !== undefined) { + requestData.rejectionThreshold = rejectionThreshold; + } return this.request({ url: `/build/${capsBuildId}/snapshot`, method: 'POST', @@ -383,26 +402,31 @@ export default class httpClient { 'Content-Type': 'application/json', projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken }, - data: { - name: snapshot.name, - url: snapshot.url, - snapshotUuid: snapshotUuid, - variantCount: variantCount, - test: { - type: ctx.testType, - source: 'cli' - }, - doRemoteDiscovery: snapshot.options.doRemoteDiscovery, - discoveryErrors: discoveryErrors, - sync: sync - } + data: requestData }, ctx.log) } - uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false) { + uploadSnapshotForCaps(ctx: Context, snapshot: ProcessedSnapshot, capsBuildId: string, capsProjectToken: string, discoveryErrors: DiscoveryErrors, variantCount: number, sync: boolean = false, approvalThreshold: number| undefined, rejectionThreshold: number| undefined) { // Use capsBuildId if provided, otherwise fallback to ctx.build.id const buildId = capsBuildId !== '' ? capsBuildId : ctx.build.id; - + + const requestData: any = { + snapshot, + test: { + type: ctx.testType, + source: 'cli' + }, + discoveryErrors: discoveryErrors, + variantCount: variantCount, + sync: sync + } + if (approvalThreshold !== undefined) { + requestData.approvalThreshold = approvalThreshold; + } + if (rejectionThreshold !== undefined) { + requestData.rejectionThreshold = rejectionThreshold; + } + return this.request({ url: `/builds/${buildId}/snapshot`, method: 'POST', @@ -410,16 +434,7 @@ export default class httpClient { 'Content-Type': 'application/json', projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken // Use capsProjectToken dynamically }, - data: { - snapshot, - test: { - type: ctx.testType, - source: 'cli' - }, - discoveryErrors: discoveryErrors, - variantCount: variantCount, - sync: sync - } + data: requestData }, ctx.log); } diff --git a/src/lib/snapshotQueue.ts b/src/lib/snapshotQueue.ts index 5548675..e36af8c 100644 --- a/src/lib/snapshotQueue.ts +++ b/src/lib/snapshotQueue.ts @@ -360,9 +360,10 @@ export default class Queue { } - if (useCapsBuildId) { this.ctx.log.info(`Using cached buildId: ${capsBuildId}`); + let approvalThreshold = snapshot?.options?.approvalThreshold || this.ctx.config.approvalThreshold; + let rejectionThreshold = snapshot?.options?.rejectionThreshold || this.ctx.config.rejectionThreshold; if (useKafkaFlowCaps) { let snapshotUuid = uuidv4(); if (snapshot?.options?.contextId && this.ctx.contextToSnapshotMap?.has(snapshot.options.contextId)) { @@ -378,9 +379,9 @@ export default class Queue { this.ctx.log.debug(`Uploading dom to S3 for snapshot using LSRS`); await this.ctx.client.sendDomToLSRSForCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken); } - await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync); + await this.ctx.client.processSnapshotCaps(this.ctx, processedSnapshot, snapshotUuid, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold); } else { - await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync); + await this.ctx.client.uploadSnapshotForCaps(this.ctx, processedSnapshot, capsBuildId, capsProjectToken, discoveryErrors, calculateVariantCountFromSnapshot(processedSnapshot, this.ctx.config), snapshot?.options?.sync, approvalThreshold, rejectionThreshold); } // Increment snapshot count for the specific buildId