1+ const chai = require ( "chai" ) ;
2+ const expect = chai . expect ;
3+ const ImageKit = require ( ".." ) ; // This will automatically pick main module (cjs bundle) as per package.json
4+
5+ const urlBuilder = require ( "../libs/url/builder" ) ;
6+
7+
8+ describe ( "Unit test cases" , function ( ) {
9+ var imagekit = new ImageKit ( {
10+ publicKey : "public_key_test" ,
11+ privateKey : "private_key_test" ,
12+ urlEndpoint : "https://test-domain.com/test-endpoint"
13+ } ) ;
14+
15+ it ( 'Authentication params check' , function ( ) {
16+ var authenticationParameters = imagekit . getAuthenticationParameters ( "your_token" , 1582269249 ) ;
17+ expect ( authenticationParameters ) . to . deep . equal ( {
18+ token : 'your_token' ,
19+ expire : 1582269249 ,
20+ signature : 'e71bcd6031016b060d349d212e23e85c791decdd'
21+ } )
22+ } ) ;
23+
24+ it ( 'Signed URL signature without slash default expiry' , function ( ) {
25+ var url = "https://test-domain.com/test-endpoint/tr:w-100/test-signed-url.png" ;
26+ var signature = urlBuilder . getSignature ( {
27+ privateKey : "private_key_test" ,
28+ url : url ,
29+ urlEndpoint :"https://test-domain.com/test-endpoint" ,
30+ expiryTimestamp : "9999999999"
31+ } )
32+ expect ( signature ) . to . be . equal ( "41b3075c40bc84147eb71b8b49ae7fbf349d0f00" )
33+ } ) ;
34+
35+ it ( 'Signed URL signature with slash default expiry' , function ( ) {
36+ var url = "https://test-domain.com/test-endpoint/tr:w-100/test-signed-url.png" ;
37+ var signature = urlBuilder . getSignature ( {
38+ privateKey : "private_key_test" ,
39+ url : url ,
40+ urlEndpoint :"https://test-domain.com/test-endpoint/" ,
41+ expiryTimestamp : "9999999999"
42+ } )
43+ expect ( signature ) . to . be . equal ( "41b3075c40bc84147eb71b8b49ae7fbf349d0f00" )
44+ } ) ;
45+
46+ it ( 'pHash distance different' , function ( ) {
47+ var pHashDistance = imagekit . pHashDistance ( "33699c96619cc69e" , "968e978414fe04ea" ) ;
48+ expect ( pHashDistance ) . to . be . equal ( 30 )
49+ } ) ;
50+
51+ it ( 'pHash distance similar' , function ( ) {
52+ var pHashDistance = imagekit . pHashDistance ( "63433b3ccf8e1ebe" , "f5d2226cd9d32b16" ) ;
53+ expect ( pHashDistance ) . to . be . equal ( 27 )
54+ } ) ;
55+
56+ it ( 'pHash distance similar reverse' , function ( ) {
57+ var pHashDistance = imagekit . pHashDistance ( "f5d2226cd9d32b16" , "63433b3ccf8e1ebe" ) ;
58+ expect ( pHashDistance ) . to . be . equal ( 27 )
59+ } ) ;
60+
61+ it ( 'pHash distance same' , function ( ) {
62+ var pHashDistance = imagekit . pHashDistance ( "33699c96619cc69e" , "33699c96619cc69e" ) ;
63+ expect ( pHashDistance ) . to . be . equal ( 0 )
64+ } ) ;
65+ } ) ;
0 commit comments