MCPcopy Create free account
hub / github.com/TestSprite/testsprite-cli / validateLatestResult

Function validateLatestResult

test/contract/p4-schema.test.ts:192–219  ·  view source on GitHub ↗
(value: unknown, label = 'LatestResult')

Source from the content-addressed store, hash-verified

190}
191
192function validateLatestResult(value: unknown, label = 'LatestResult'): void {
193 expect(value, `${label}: must be an object`).toBeTypeOf('object');
194 expect(value, `${label}: must not be null`).not.toBeNull();
195 const obj = value as Record<string, unknown>;
196 expectRequired(obj, LATEST_RESULT_REQUIRED, label);
197 expectKeysMatch(obj, LATEST_RESULT_ALL, label);
198 expect(typeof obj.testId, `${label}.testId`).toBe('string');
199 expect(PUBLIC_STATUSES, `${label}.status`).toContain(obj.status);
200 expectStringOrNull(obj.startedAt, `${label}.startedAt`);
201 expectStringOrNull(obj.finishedAt, `${label}.finishedAt`);
202 expectStringOrNull(obj.videoUrl, `${label}.videoUrl`);
203 expectStringOrNull(obj.failureAnalysisUrl, `${label}.failureAnalysisUrl`);
204 expect(typeof obj.snapshotId, `${label}.snapshotId`).toBe('string');
205 expectStringOrNull(obj.runIdIfAvailable, `${label}.runIdIfAvailable`);
206 expectStringOrNull(obj.codeVersion, `${label}.codeVersion`);
207 expectStringOrNull(obj.targetUrl, `${label}.targetUrl`);
208 // D1 — optional provenance discriminator; when present must be a known enum
209 // value or null (a null `targetUrl` should carry 'unresolved' or null).
210 if ('targetUrlSource' in obj) {
211 expect(TARGET_URL_SOURCES.has(obj.targetUrlSource), `${label}.targetUrlSource`).toBe(true);
212 }
213 if (obj.failedStepIndex !== null) {
214 expect(typeof obj.failedStepIndex, `${label}.failedStepIndex`).toBe('number');
215 expect((obj.failedStepIndex as number) >= 1, `${label}.failedStepIndex >= 1`).toBe(true);
216 }
217 expect(FAILURE_KINDS.has(obj.failureKind), `${label}.failureKind`).toBe(true);
218 validateResultSummary(obj.summary, `${label}.summary`);
219}
220
221describe('P4 schema contract — fixtures match the OpenAPI shapes', () => {
222 it('TestCode (inline) — every required field present, no extras', () => {

Callers 1

p4-schema.test.tsFile · 0.85

Calls 4

validateResultSummaryFunction · 0.85
expectRequiredFunction · 0.70
expectKeysMatchFunction · 0.70
expectStringOrNullFunction · 0.70

Tested by

no test coverage detected