@@ -3,14 +3,155 @@ import { send, log, logError, runIntegrationTest } from "./testLibrary.mjs";
3
3
4
4
async function helloTrump ( ) {
5
5
const reply = await send ( "Hi" ) ;
6
- assert ( reply . length > 10 ) ;
6
+ assert ( reply . length > 0 , "Response should not be empty" ) ;
7
+ const response = reply [ 0 ] ;
8
+ assert ( response . text , "Response should have text property" ) ;
9
+ assert (
10
+ response . text . length > 10 ,
11
+ `Response should be longer than 10 characters, is ${ reply . length } `
12
+ ) ;
7
13
}
14
+ helloTrump . description = "Hello Trump" ;
15
+ helloTrump . skipIf = ! process . env . OPENAI_API_KEY ;
8
16
9
- async function coinbaseTest ( ) {
10
- // TODO
17
+ async function coinbaseCommerceChargeTest ( ) {
18
+ const chargeDescription = "Exclusive digital artwork collection" ;
19
+ const chargeRequest = `Create a charge for $100 USD for Digital Art NFT with description '${ chargeDescription } '` ;
20
+ const response = await send ( chargeRequest ) ;
21
+
22
+ // Verify response structure
23
+ assert ( Array . isArray ( response ) , "Response should be an array" ) ;
24
+ assert ( response . length === 2 , "Response should contain two messages" ) ;
25
+
26
+ // Verify initial response
27
+ const initialResponse = response [ 0 ] ;
28
+ assert . strictEqual ( initialResponse . action , "CREATE_CHARGE" ) ;
29
+
30
+ // Verify charge creation response
31
+ const chargeResponse = response [ 1 ] ;
32
+ assert (
33
+ chargeResponse . text . startsWith ( "Charge created successfully:" ) ,
34
+ "Should indicate successful charge creation"
35
+ ) ;
36
+ assert (
37
+ chargeResponse . text . includes ( "https://commerce.coinbase.com/pay/" ) ,
38
+ "Should contain valid Coinbase Commerce URL"
39
+ ) ;
40
+
41
+ // Verify attachment structure
42
+ assert (
43
+ Array . isArray ( chargeResponse . attachments ) ,
44
+ "Should have attachments array"
45
+ ) ;
46
+ assert (
47
+ chargeResponse . attachments . length === 1 ,
48
+ "Should have one attachment"
49
+ ) ;
50
+
51
+ const attachment = chargeResponse . attachments [ 0 ] ;
52
+ assert . strictEqual ( attachment . source , "coinbase" ) ;
53
+ assert . strictEqual ( attachment . title , "Coinbase Commerce Charge" ) ;
54
+ assert ( attachment . id , "Should have an ID" ) ;
55
+ assert ( attachment . url , "Should have a charge ID URL" ) ;
56
+ assert (
57
+ attachment . description . startsWith ( "Charge ID:" ) ,
58
+ "Should have charge ID description"
59
+ ) ;
60
+ assert ( attachment . text . startsWith ( "Pay here:" ) , "Should have payment URL" ) ;
61
+ assert (
62
+ attachment . text . includes ( "https://commerce.coinbase.com/pay/" ) ,
63
+ "Should have valid Coinbase Commerce URL"
64
+ ) ;
65
+
66
+ // Store the created charge ID for later comparison
67
+ const createdChargeId = attachment . id ;
68
+ const createdChargeUrl = attachment . url ;
69
+
70
+ // Fetch and verify all charges
71
+ const chargesResponse = await send ( "Fetch all charges" ) ;
72
+
73
+ // Verify response structure
74
+ assert (
75
+ Array . isArray ( chargesResponse ) ,
76
+ "Charges response should be an array"
77
+ ) ;
78
+ assert (
79
+ chargesResponse . length === 2 ,
80
+ "Should have two messages (prompt and response)"
81
+ ) ;
82
+
83
+ // Verify charges data
84
+ const charges = chargesResponse [ 1 ] . attachments ;
85
+ assert ( Array . isArray ( charges ) , "Charges should be an array" ) ;
86
+ assert ( charges . length > 0 , "Should have at least one charge" ) ;
87
+
88
+ // Verify each charge has required properties
89
+ charges . forEach ( ( charge ) => {
90
+ assert ( charge . id , "Each charge should have an id" ) ;
91
+ assert ( charge . hosted_url , "Each charge should have a hosted_url" ) ;
92
+ assert (
93
+ charge . hosted_url . includes ( "commerce.coinbase.com/pay/" ) ,
94
+ "hosted_url should be a valid Coinbase URL"
95
+ ) ;
96
+ assert ( charge . web3_data , "Each charge should have web3_data object" ) ;
97
+ } ) ;
98
+
99
+ // Verify the previously created charge exists in the list
100
+ const foundCharge = charges . find ( ( charge ) => charge . id === createdChargeId ) ;
101
+ assert ( foundCharge , "Previously created charge should exist in the list" ) ;
102
+ assert . strictEqual (
103
+ foundCharge . hosted_url ,
104
+ createdChargeUrl ,
105
+ "Hosted URL should match"
106
+ ) ;
107
+ assert . strictEqual (
108
+ foundCharge . description ,
109
+ chargeDescription ,
110
+ "Description should match"
111
+ ) ;
112
+
113
+ // Test GetChargeDetails action
114
+ const getDetailsResponse = await send (
115
+ `Get details for charge ID: ${ createdChargeId } `
116
+ ) ;
117
+
118
+ // Verify response structure for charge details
119
+ assert (
120
+ Array . isArray ( getDetailsResponse ) ,
121
+ "GetChargeDetails response should be an array"
122
+ ) ;
123
+ assert (
124
+ getDetailsResponse . length === 2 ,
125
+ "Should have two messages (prompt and response)"
126
+ ) ;
127
+
128
+ // Verify charge details response
129
+ const detailsResponse = getDetailsResponse [ 1 ] ;
130
+ assert (
131
+ Array . isArray ( detailsResponse . attachments ) ,
132
+ "Should have attachments array"
133
+ ) ;
134
+
135
+ const detailsAttachment = detailsResponse . attachments [ 0 ] ;
136
+
137
+ const chargeData = JSON . parse ( detailsAttachment . description ) ;
138
+
139
+ assert . equal (
140
+ chargeData . data . hosted_url ,
141
+ createdChargeUrl ,
142
+ "Hosted URLs should match"
143
+ ) ;
144
+ assert . equal (
145
+ chargeData . data . description ,
146
+ chargeDescription ,
147
+ "Charge description should match"
148
+ ) ;
11
149
}
150
+ coinbaseCommerceChargeTest . description = "Coinbase Commerce Charge" ;
151
+ coinbaseCommerceChargeTest . skipIf =
152
+ ! process . env . OPENAI_API_KEY || ! process . env . COINBASE_COMMERCE_KEY ;
12
153
13
- const testSuite = [ helloTrump ] ; // Add tests here
154
+ const testSuite = [ helloTrump , coinbaseCommerceChargeTest ] ;
14
155
try {
15
156
for ( const test of testSuite ) await runIntegrationTest ( test ) ;
16
157
} catch ( error ) {
0 commit comments