@@ -4,40 +4,34 @@ import { InferenceResponse, LocalResponse } from "../../../src";
44
55import path from "path" ;
66import { V2_RESOURCE_PATH } from "../../index" ;
7+ import { Buffer } from "node:buffer" ;
78
8- const signature : string = "a1bc9012fa63539d602f163d8980604a0cf2b2ae88e56009cfa1db33382736cf " ;
9+ const signature : string = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be " ;
910const dummySecretKey : string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH" ;
1011const filePath : string = path . join ( V2_RESOURCE_PATH , "inference/standard_field_types.json" ) ;
1112
13+ async function assertLocalResponse ( localResponse : LocalResponse ) {
14+ await localResponse . init ( ) ;
15+ expect ( localResponse . asDict ( ) ) . to . not . be . null ;
16+ expect ( localResponse . isValidHmacSignature ( dummySecretKey , "invalid signature" ) ) . to . be . false ;
17+ expect ( localResponse . getHmacSignature ( dummySecretKey ) ) . to . eq ( signature ) ;
18+ expect ( localResponse . isValidHmacSignature ( dummySecretKey , signature ) ) . to . be . true ;
19+ }
20+
1221describe ( "MindeeV2 - Load Local Response" , ( ) => {
1322 it ( "should load a string properly." , async ( ) => {
1423 const fileObj = await fs . readFile ( filePath , { encoding : "utf-8" } ) ;
15- const localResponse = new LocalResponse ( fileObj ) ;
16- await localResponse . init ( ) ;
17- expect ( localResponse . asDict ( ) ) . to . not . be . null ;
18- expect ( localResponse . isValidHmacSignature ( dummySecretKey , "invalid signature" ) ) . to . be . false ;
19- expect ( localResponse . getHmacSignature ( dummySecretKey ) ) . to . eq ( signature ) ;
20- expect ( localResponse . isValidHmacSignature ( dummySecretKey , signature ) ) . to . be . true ;
24+ await assertLocalResponse ( new LocalResponse ( fileObj ) ) ;
2125 } ) ;
2226
2327 it ( "should load a file properly." , async ( ) => {
24- const localResponse = new LocalResponse ( filePath ) ;
25- await localResponse . init ( ) ;
26- expect ( localResponse . asDict ( ) ) . to . not . be . null ;
27- expect ( localResponse . isValidHmacSignature ( dummySecretKey , "invalid signature" ) ) . to . be . false ;
28- expect ( localResponse . getHmacSignature ( dummySecretKey ) ) . to . eq ( signature ) ;
29- expect ( localResponse . isValidHmacSignature ( dummySecretKey , signature ) ) . to . be . true ;
28+ await assertLocalResponse ( new LocalResponse ( filePath ) ) ;
3029 } ) ;
3130
3231 it ( "should load a buffer properly." , async ( ) => {
3332 const fileStr = ( await fs . readFile ( filePath , { encoding : "utf-8" } ) ) . replace ( / \r / g, "" ) . replace ( / \n / g, "" ) ;
3433 const fileBuffer = Buffer . from ( fileStr , "utf-8" ) ;
35- const localResponse = new LocalResponse ( fileBuffer ) ;
36- await localResponse . init ( ) ;
37- expect ( localResponse . asDict ( ) ) . to . not . be . null ;
38- expect ( localResponse . isValidHmacSignature ( dummySecretKey , "invalid signature" ) ) . to . be . false ;
39- expect ( localResponse . getHmacSignature ( dummySecretKey ) ) . to . eq ( signature ) ;
40- expect ( localResponse . isValidHmacSignature ( dummySecretKey , signature ) ) . to . be . true ;
34+ await assertLocalResponse ( new LocalResponse ( fileBuffer ) ) ;
4135 } ) ;
4236
4337 it ( "should deserialize a prediction." , async ( ) => {
0 commit comments