Skip to content

Commit 00efe9f

Browse files
test success fetch.spec.ts
1 parent 691471b commit 00efe9f

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

exampleLitActions/test/fetch.spec.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
11
import { expect } from 'chai';
2-
import { fetch } from '../src/fetch'; // Adjust the path as needed
2+
import { fetch } from '../src/fetch';
3+
import * as dotenv from 'dotenv';
34

4-
describe('Lit Action fetch test', function() {
5-
// Increase timeout if needed for API calls
6-
this.timeout(30000);
5+
// Load environment variables from .env file if present
6+
dotenv.config();
77

8-
it('should execute a fetch inside a Lit Action', async () => {
8+
describe('Lit Action Weather-Based Test', function() {
9+
// Increase timeout for API calls and blockchain interactions
10+
this.timeout(60000);
11+
12+
before(function() {
13+
// Skip tests if required environment variables are missing
14+
if (!process.env.ETHEREUM_PRIVATE_KEY) {
15+
console.warn('⚠️ Tests require ETHEREUM_PRIVATE_KEY environment variable');
16+
this.skip();
17+
}
18+
});
19+
20+
it('should execute the fetch function and handle the response appropriately', async function() {
21+
// Execute the fetch function
922
const result = await fetch();
1023

11-
expect(result.success, 'Fetch should execute successfully').to.be.true;
24+
// Log the result for debugging
25+
console.log('Test result:', {
26+
success: result.success,
27+
hasResponse: !!result.response,
28+
error: result.error
29+
});
1230

13-
if (!result.success) {
14-
expect(result.error, 'There should be no errors').to.be.undefined;
31+
if (result.success) {
32+
// If successful, we should have either:
33+
// 1. A response with signatures (if temperature > 60°F)
34+
// 2. A response without signatures (if temperature < 60°F)
35+
console.log('Function executed successfully');
36+
37+
if (result.response) {
38+
console.log('Got response - temperature appears to be above 60°F');
39+
console.log('Response keys:', Object.keys(result.response));
40+
} else {
41+
console.log('No response - temperature appears to be below 60°F');
42+
}
43+
} else {
44+
// If not successful, we should have an error
45+
console.error('Function failed with error:', result.error);
46+
// This is a legitimate test failure - the function should not throw errors
47+
expect.fail('The fetch function threw an error: ' + result.error);
1548
}
1649

17-
// Add more assertions as needed
18-
expect(result.response).to.not.be.null;
50+
// The only thing we can consistently assert is that the function executed
51+
// and returned an object with the expected properties
52+
expect(result).to.have.property('success');
53+
54+
// We don't make assertions about response content as it depends on actual weather
1955
});
2056
});

0 commit comments

Comments
 (0)