Skip to content

Commit

Permalink
test: Change tests for new response in ai_extract_structured (box/b…
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build committed Jan 29, 2025
1 parent da41baa commit f1f39e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "cf82faa", "specHash": "1fdcbef", "version": "1.11.0" }
{ "engineHash": "a74691d", "specHash": "1fdcbef", "version": "1.11.0" }
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ export async function delayInSeconds(seconds: number): Promise<void> {
* @returns Value from object raw data.
*/
export function getValueFromObjectRawData(obj: any, key: string): any {
if (obj && typeof obj === 'object' && obj.rawData) {
return obj.rawData[key];
if (!obj || typeof obj !== 'object' || !obj.rawData) {
return undefined;
}
return undefined;
return key.split('.').reduce((value, k) => value?.[k], obj.rawData);
}

/**
Expand Down
52 changes: 35 additions & 17 deletions src/test/ai.generated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,42 +384,51 @@ test('testAIExtractStructuredWithFields', async function testAIExtractStructured
} satisfies AiExtractStructured);
if (
!(
(toString(getValueFromObjectRawData(response, 'firstName')) as string) ==
'John'
(toString(
getValueFromObjectRawData(response, 'answer.hobby'),
) as string) == (['guitar'].map(toString).join(',') as string)
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(getValueFromObjectRawData(response, 'lastName')) as string) ==
'Doe'
(toString(
getValueFromObjectRawData(response, 'answer.firstName'),
) as string) == 'John'
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(
getValueFromObjectRawData(response, 'dateOfBirth'),
) as string) == '1990-07-04'
getValueFromObjectRawData(response, 'answer.lastName'),
) as string) == 'Doe'
)
) {
throw new Error('Assertion failed');
}
if (
!((toString(getValueFromObjectRawData(response, 'age')) as string) == '34')
!(
(toString(
getValueFromObjectRawData(response, 'answer.dateOfBirth'),
) as string) == '1990-07-04'
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(getValueFromObjectRawData(response, 'hobby')) as string) ==
(['guitar'].map(toString).join(',') as string)
(toString(getValueFromObjectRawData(response, 'answer.age')) as string) ==
'34'
)
) {
throw new Error('Assertion failed');
}
if (!(response.completionReason == 'done')) {
throw new Error('Assertion failed');
}
await client.files.deleteFileById(file.id);
});
test('testAIExtractStructuredWithMetadataTemplate', async function testAIExtractStructuredWithMetadataTemplate(): Promise<any> {
Expand Down Expand Up @@ -491,42 +500,51 @@ test('testAIExtractStructuredWithMetadataTemplate', async function testAIExtract
} satisfies AiExtractStructured);
if (
!(
(toString(getValueFromObjectRawData(response, 'firstName')) as string) ==
'John'
(toString(
getValueFromObjectRawData(response, 'answer.firstName'),
) as string) == 'John'
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(getValueFromObjectRawData(response, 'lastName')) as string) ==
'Doe'
(toString(
getValueFromObjectRawData(response, 'answer.lastName'),
) as string) == 'Doe'
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(
getValueFromObjectRawData(response, 'dateOfBirth'),
getValueFromObjectRawData(response, 'answer.dateOfBirth'),
) as string) == '1990-07-04T00:00:00Z'
)
) {
throw new Error('Assertion failed');
}
if (
!((toString(getValueFromObjectRawData(response, 'age')) as string) == '34')
!(
(toString(getValueFromObjectRawData(response, 'answer.age')) as string) ==
'34'
)
) {
throw new Error('Assertion failed');
}
if (
!(
(toString(getValueFromObjectRawData(response, 'hobby')) as string) ==
(['guitar'].map(toString).join(',') as string)
(toString(
getValueFromObjectRawData(response, 'answer.hobby'),
) as string) == (['guitar'].map(toString).join(',') as string)
)
) {
throw new Error('Assertion failed');
}
if (!(response.completionReason == 'done')) {
throw new Error('Assertion failed');
}
await client.metadataTemplates.deleteMetadataTemplate(
'enterprise' as DeleteMetadataTemplateScope,
template.templateKey!,
Expand Down

0 comments on commit f1f39e1

Please sign in to comment.