1
1
import { afterEach , describe , expect , it , vi } from "vitest" ;
2
2
3
- import { FormatWebhookErrorResult } from "@/handlers/shared" ;
3
+ import { buildSyncWebhookResponsePayload , FormatWebhookErrorResult } from "@/handlers/shared" ;
4
4
import { SaleorWebhookValidator } from "@/handlers/shared/saleor-webhook-validator" ;
5
5
import { MockAPL } from "@/test-utils/mock-apl" ;
6
6
@@ -27,20 +27,20 @@ describe("AWS Lambda SaleorSyncWebhook", () => {
27
27
it ( "returns valid URL when baseUrl has Lambda stage" , ( ) => {
28
28
const webhook = new SaleorSyncWebhook ( webhookConfig ) ;
29
29
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/prod" ) . targetUrl ) . toBe (
30
- "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes"
30
+ "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes" ,
31
31
) ;
32
32
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/prod/" ) . targetUrl ) . toBe (
33
- "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes"
33
+ "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes" ,
34
34
) ;
35
35
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/test" ) . targetUrl ) . toBe (
36
- "https://aws-lambda.com/test/api/webhooks/checkout-calculate-taxes"
36
+ "https://aws-lambda.com/test/api/webhooks/checkout-calculate-taxes" ,
37
37
) ;
38
38
} ) ;
39
39
40
40
it ( "returns valid URL when baseURl doesn't have lambda stage ($default stage)" , ( ) => {
41
41
const webhook = new SaleorSyncWebhook ( webhookConfig ) ;
42
42
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/" ) . targetUrl ) . toBe (
43
- "https://aws-lambda.com/api/webhooks/checkout-calculate-taxes"
43
+ "https://aws-lambda.com/api/webhooks/checkout-calculate-taxes" ,
44
44
) ;
45
45
} ) ;
46
46
@@ -50,16 +50,16 @@ describe("AWS Lambda SaleorSyncWebhook", () => {
50
50
webhookPath : `/${ webhookConfig . webhookPath } ` ,
51
51
} ) ;
52
52
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/prod" ) . targetUrl ) . toBe (
53
- "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes"
53
+ "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes" ,
54
54
) ;
55
55
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/prod/" ) . targetUrl ) . toBe (
56
- "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes"
56
+ "https://aws-lambda.com/prod/api/webhooks/checkout-calculate-taxes" ,
57
57
) ;
58
58
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/test" ) . targetUrl ) . toBe (
59
- "https://aws-lambda.com/test/api/webhooks/checkout-calculate-taxes"
59
+ "https://aws-lambda.com/test/api/webhooks/checkout-calculate-taxes" ,
60
60
) ;
61
61
expect ( webhook . getWebhookManifest ( "https://aws-lambda.com/" ) . targetUrl ) . toBe (
62
- "https://aws-lambda.com/api/webhooks/checkout-calculate-taxes"
62
+ "https://aws-lambda.com/api/webhooks/checkout-calculate-taxes" ,
63
63
) ;
64
64
} ) ;
65
65
} ) ;
@@ -88,15 +88,15 @@ describe("AWS Lambda SaleorSyncWebhook", () => {
88
88
89
89
const handler : AwsLambdaSyncWebhookHandler < Payload > = vi
90
90
. fn ( )
91
- . mockImplementation ( async ( _event , _context , ctx ) => ( {
91
+ . mockImplementation ( async ( ) => ( {
92
92
statusCode : 200 ,
93
93
body : JSON . stringify (
94
- ctx . buildResponse ( {
94
+ buildSyncWebhookResponsePayload < "CHECKOUT_CALCULATE_TAXES" > ( {
95
95
lines : [ { tax_rate : 8 , total_net_amount : 10 , total_gross_amount : 10.8 } ] ,
96
96
shipping_price_gross_amount : 2.16 ,
97
97
shipping_tax_rate : 8 ,
98
98
shipping_price_net_amount : 2 ,
99
- } )
99
+ } ) ,
100
100
) ,
101
101
} ) ) ;
102
102
const wrappedHandler = saleorSyncWebhook . createHandler ( handler ) ;
0 commit comments