Skip to content

Commit ecde6a5

Browse files
refactor: streamline correlation ID generation and expected output validation in classifyImage tests
1 parent 25c993d commit ecde6a5

1 file changed

Lines changed: 8 additions & 28 deletions

File tree

__tests__/unit/main.test.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ describe('classifyImage function', () => {
4747
});
4848

4949
// Generate 10 unique correlationIds
50-
const correlationIds =
51-
[
52-
randomUUID().toString(),
53-
randomUUID().toString(),
54-
randomUUID().toString()
55-
]
50+
const correlationIds = Array.from({ length: 10 }, () => randomUUID().toString());
5651

5752
correlationIds.sort((a, b) => a.localeCompare(b));
5853

@@ -112,35 +107,20 @@ describe('classifyImage function', () => {
112107
expect(outputs).toBeDefined();
113108
// Check that all correlationIds are present in the outputs
114109
expect(outputs.length).toBe(correlationIds.length);
115-
expect(outputs).toMatchObject([
116-
{
117-
correlationId: correlationIds[0],
118-
classifications: expect.arrayContaining([
119-
{
120-
label: expect.any(String),
121-
weight: expect.any(Number)
122-
}
123-
])
124-
} as ClassificationOutput,
125-
{
126-
correlationId: correlationIds[1],
127-
classifications: expect.arrayContaining([
128-
{
129-
label: expect.any(String),
130-
weight: expect.any(Number)
131-
}
132-
])
133-
} as ClassificationOutput,
110+
111+
const expectedOutputs = correlationIds.map(id =>(
134112
{
135-
correlationId: correlationIds[2],
113+
correlationId: id,
136114
classifications: expect.arrayContaining([
137115
{
138116
label: expect.any(String),
139117
weight: expect.any(Number)
140118
}
141119
])
142-
} as ClassificationOutput
143-
]);
120+
}
121+
));
122+
123+
expect(outputs).toMatchObject(expectedOutputs);
144124
}, 120000);
145125

146126
it('should classify Steamboat-willie.jpg and return responses (integration smoke test)', async ({expect, annotate}) => {

0 commit comments

Comments
 (0)