You've already forked tf2wikipricing
test: fix unit tests for WebExtension build
This commit is contained in:
@@ -58,11 +58,11 @@ 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)
|
||||
(priceUsingPricesTF as jest.Mock).mockResolvedValue(mockPriceResponse);
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockPriceResponse);
|
||||
|
||||
const result = await fetchPrice(mockToken, mockDefIndex + ";" + mockQuality)
|
||||
|
||||
expect(priceUsingPricesTF).toHaveBeenCalledWith(mockToken, `${mockDefIndex};${mockQuality}`)
|
||||
expect(setStorageValue).toHaveBeenCalled()
|
||||
expect(result.metal).not.toBe(mockCachedData.metal)
|
||||
expect(result.metal).toBe(mockPriceResponse.metal)
|
||||
@@ -73,8 +73,8 @@ describe('Price Service', () => {
|
||||
})
|
||||
|
||||
test('fetchPrice handles pricing API errors', async () => {
|
||||
const testError = 500;
|
||||
(priceUsingPricesTF as jest.Mock).mockRejectedValue(testError);
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockResolvedValue(null);
|
||||
(priceUsingPricesTF 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()
|
||||
@@ -82,11 +82,11 @@ describe('Price Service', () => {
|
||||
|
||||
test('fetchKeyPrice uses correct parameters', async () => {
|
||||
(getStorageValue as jest.Mock).mockResolvedValue(null);
|
||||
(priceUsingPricesTF as jest.Mock).mockResolvedValue(mockKeyPriceResponse)
|
||||
(priceUsingPricesTF as jest.Mock).mockResolvedValue(mockKeyPriceResponse);
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockKeyPriceResponse);
|
||||
|
||||
const result = await fetchKeyPrice(mockToken)
|
||||
|
||||
expect(priceUsingPricesTF).toHaveBeenCalledWith(mockToken, `${defindex_key};6`)
|
||||
expect(result.keys).toBe(0) // A key cannot cost a key :P
|
||||
expect(result.metal).toBe(mockKeyPriceResponse.metal)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user