From 537c3fe06e43af3dffa63f9da4ccb67838587d7f Mon Sep 17 00:00:00 2001 From: rapture-party Date: Sat, 2 May 2026 15:59:24 -0400 Subject: [PATCH] test: update tests for new pricing service --- __tests__/priceService.test.ts | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/__tests__/priceService.test.ts b/__tests__/priceService.test.ts index 29b719a..aaf5616 100644 --- a/__tests__/priceService.test.ts +++ b/__tests__/priceService.test.ts @@ -1,22 +1,21 @@ import { describe, expect, test, jest, mock, beforeEach } from "bun:test"; import { ItemPriceData, fetchPrice, fetchKeyPrice } from '../src/content/priceService' -import { PricesResponse, priceUsingPricesTF } from '../src/content/pricing/pricestf' +import { PricesResponse, priceUsingPricedb } from '../src/content/pricing/pricedb' import { getStorageValue, setStorageValue } from '../src/content/storage' import { defindex_key } from "../src/content/config"; -// Mock the storage module +// Mock storage module mock.module('../src/content/storage', () => ({ getStorageValue: jest.fn(), setStorageValue: jest.fn() })) -// Mock the pricing module -mock.module('../src/content/pricing/pricestf', () => ({ - priceUsingPricesTF: jest.fn() +// Mock pricing module +mock.module('../src/content/pricing/pricedb', () => ({ + priceUsingPricedb: jest.fn() })) describe('Price Service', () => { - const mockToken = 'test-token' const mockDefIndex = 105 // Brigade Helm const mockQuality = 11 // Strange const mockSku = `${mockDefIndex};${mockQuality}` @@ -49,7 +48,7 @@ describe('Price Service', () => { test('fetchPrice returns cached data if available and not expired', async () => { (getStorageValue as jest.Mock).mockResolvedValue(mockCachedData) - const result = await fetchPrice(mockToken, mockDefIndex + ";" + mockQuality) + const result = await fetchPrice(mockDefIndex + ";" + mockQuality) expect(getStorageValue).toHaveBeenCalledWith(expect.stringContaining(mockSku), null) expect(result).toEqual(mockCachedData) @@ -58,34 +57,30 @@ describe('Price Service', () => { test('fetchPrice fetches new data when cache is expired', async () => { const expiredCache: ItemPriceData = { ...mockCachedData, update: new Date(Date.now() - 2 * mockTtl).getTime() }; (getStorageValue as jest.Mock).mockResolvedValue(expiredCache); - (priceUsingPricesTF as jest.Mock).mockResolvedValue(mockPriceResponse); + (priceUsingPricedb as jest.Mock).mockResolvedValue(mockPriceResponse); (chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockPriceResponse); - const result = await fetchPrice(mockToken, mockDefIndex + ";" + mockQuality) + const result = await fetchPrice(mockDefIndex + ";" + mockQuality) expect(setStorageValue).toHaveBeenCalled() expect(result.metal).not.toBe(mockCachedData.metal) expect(result.metal).toBe(mockPriceResponse.metal) }) - test('fetchPrice rejects with 401 when no token provided', async () => { - await expect(fetchPrice('', mockDefIndex + ";" + mockQuality)).rejects.toThrow() - }) - test('fetchPrice handles pricing API errors', async () => { (chrome.runtime.sendMessage as jest.Fn).mockResolvedValue(null); - (priceUsingPricesTF as jest.Mock).mockImplementation(() => Promise.reject(new Error('500 Internal Server Error'))); + (priceUsingPricedb as jest.Mock).mockImplementation(() => Promise.reject(new Error('500 Internal Server Error'))); (getStorageValue as jest.Mock).mockResolvedValue(null) - await expect(fetchPrice(mockToken, mockDefIndex + ";" + mockQuality)).rejects.toThrow() + await expect(fetchPrice(mockDefIndex + ";" + mockQuality)).rejects.toThrow() }) test('fetchKeyPrice uses correct parameters', async () => { (getStorageValue as jest.Mock).mockResolvedValue(null); - (priceUsingPricesTF as jest.Mock).mockResolvedValue(mockKeyPriceResponse); + (priceUsingPricedb as jest.Mock).mockResolvedValue(mockKeyPriceResponse); (chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockKeyPriceResponse); - const result = await fetchKeyPrice(mockToken) + const result = await fetchKeyPrice() expect(result.keys).toBe(0) // A key cannot cost a key :P expect(result.metal).toBe(mockKeyPriceResponse.metal)