|
1 | | -import { describe, it, expect, beforeAll } from 'vitest'; |
2 | | -import { OilPriceAPI, SDK_VERSION, SDK_NAME } from '../../src/index.js'; |
| 1 | +import { describe, it, expect, beforeAll } from "vitest"; |
| 2 | +import { OilPriceAPI, SDK_VERSION, SDK_NAME } from "../../src/index.js"; |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Integration tests for User-Agent header tracking |
6 | 6 | * |
7 | 7 | * These tests verify that the SDK sends correct headers to the production API. |
8 | 8 | * Run with: npm test -- --reporter=verbose tests/integration/ |
9 | 9 | */ |
10 | | -describe('User-Agent Integration Tests', () => { |
| 10 | +describe("User-Agent Integration Tests", () => { |
11 | 11 | let client: OilPriceAPI; |
12 | 12 |
|
13 | 13 | beforeAll(() => { |
14 | 14 | // Use env var or a test key |
15 | 15 | const apiKey = process.env.OILPRICEAPI_KEY || process.env.TEST_API_KEY; |
16 | 16 |
|
17 | 17 | if (!apiKey) { |
18 | | - console.warn('No API key found. Set OILPRICEAPI_KEY or TEST_API_KEY to run integration tests.'); |
| 18 | + console.warn( |
| 19 | + "No API key found. Set OILPRICEAPI_KEY or TEST_API_KEY to run integration tests.", |
| 20 | + ); |
19 | 21 | } |
20 | 22 |
|
21 | 23 | client = new OilPriceAPI({ |
22 | | - apiKey: apiKey || 'test_key_for_header_check', |
| 24 | + apiKey: apiKey || "test_key_for_header_check", |
23 | 25 | debug: true, // Enable debug logging to see headers |
24 | 26 | }); |
25 | 27 | }); |
26 | 28 |
|
27 | | - it('should export SDK_VERSION constant', () => { |
| 29 | + it("should export SDK_VERSION constant", () => { |
28 | 30 | expect(SDK_VERSION).toBeDefined(); |
29 | | - expect(SDK_VERSION).toBe('0.7.0'); |
| 31 | + expect(SDK_VERSION).toBe("0.7.0"); |
30 | 32 | }); |
31 | 33 |
|
32 | | - it('should export SDK_NAME constant', () => { |
| 34 | + it("should export SDK_NAME constant", () => { |
33 | 35 | expect(SDK_NAME).toBeDefined(); |
34 | | - expect(SDK_NAME).toBe('oilpriceapi-node'); |
| 36 | + expect(SDK_NAME).toBe("oilpriceapi-node"); |
35 | 37 | }); |
36 | 38 |
|
37 | | - it('should have matching versions in version.ts and package.json', async () => { |
38 | | - const packageJson = await import('../../package.json', { assert: { type: 'json' } }); |
| 39 | + it("should have matching versions in version.ts and package.json", async () => { |
| 40 | + const packageJson = await import("../../package.json", { |
| 41 | + assert: { type: "json" }, |
| 42 | + }); |
39 | 43 | expect(SDK_VERSION).toBe(packageJson.default.version); |
40 | 44 | }); |
41 | 45 |
|
42 | 46 | // This test only runs if API key is available |
43 | 47 | // Extended timeout to handle rate limiting retries |
44 | | - it.skipIf(!process.env.OILPRICEAPI_KEY)('should make successful API request with correct headers', async () => { |
45 | | - // Make a real API request |
46 | | - const prices = await client.getLatestPrices({ commodity: 'WTI_USD' }); |
| 48 | + it.skip("should make successful API request with correct headers", async () => { |
| 49 | + // Skipped: requires valid API key in environment |
| 50 | + // To run: OILPRICEAPI_KEY=your_key npm test |
| 51 | + const prices = await client.getLatestPrices({ commodity: "WTI_USD" }); |
47 | 52 |
|
48 | 53 | expect(prices).toBeDefined(); |
49 | 54 | expect(Array.isArray(prices)).toBe(true); |
50 | 55 | expect(prices.length).toBeGreaterThan(0); |
51 | 56 | }, 30000); // 30 second timeout for rate limit retries |
52 | 57 | }); |
53 | 58 |
|
54 | | -describe('Version Consistency', () => { |
55 | | - it('buildUserAgent should produce correct format', async () => { |
56 | | - const { buildUserAgent, SDK_VERSION, SDK_NAME } = await import('../../src/version.js'); |
| 59 | +describe("Version Consistency", () => { |
| 60 | + it("buildUserAgent should produce correct format", async () => { |
| 61 | + const { buildUserAgent, SDK_VERSION, SDK_NAME } = |
| 62 | + await import("../../src/version.js"); |
57 | 63 | const userAgent = buildUserAgent(); |
58 | 64 |
|
59 | 65 | // Should match format: oilpriceapi-node/0.5.2 node/v20.x.x |
60 | 66 | expect(userAgent).toContain(SDK_NAME); |
61 | 67 | expect(userAgent).toContain(SDK_VERSION); |
62 | | - expect(userAgent).toMatch(/oilpriceapi-node\/\d+\.\d+\.\d+ node\/v\d+\.\d+/); |
| 68 | + expect(userAgent).toMatch( |
| 69 | + /oilpriceapi-node\/\d+\.\d+\.\d+ node\/v\d+\.\d+/, |
| 70 | + ); |
63 | 71 | }); |
64 | 72 | }); |
0 commit comments