You've already forked tf2wikipricing
test: fix unit tests for WebExtension build
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, test, mock } from "bun:test";
|
||||
import { describe, expect, test, mock, beforeEach, jest } from "bun:test";
|
||||
import { ItemSchema, ItemSlot, getItemIndexByName, getTradableStatusByDefindex, getTradableStatusByName, linkBotkillerVariants, linkFestiveVariants, prepareSchema } from '../src/content/schemaService'
|
||||
|
||||
// Mock the storage and log functions
|
||||
@@ -13,6 +13,24 @@ mock.module('../src/content/utils/log', () => ({
|
||||
logError: mock(() => {})
|
||||
}));
|
||||
|
||||
const mockSchemaResponse = [
|
||||
{
|
||||
defindex: 1,
|
||||
item_name: 'Test Item',
|
||||
item_slot: 'misc',
|
||||
attributes: [
|
||||
{ "name": "cannot trade", "class": "cannot_trade", "value": 1 }
|
||||
],
|
||||
capabilities: {}
|
||||
},
|
||||
{
|
||||
defindex: 208,
|
||||
item_name: 'Flame Thrower',
|
||||
item_slot: 'primary',
|
||||
capabilities: { can_killstreakify: true }
|
||||
}
|
||||
]
|
||||
|
||||
const mockSchema: ItemSchema = {
|
||||
'21': {
|
||||
name: 'Flame Thrower',
|
||||
@@ -89,6 +107,7 @@ const mockSchema: ItemSchema = {
|
||||
}
|
||||
|
||||
describe('Schema Service', () => {
|
||||
|
||||
test('getItemIndexByName returns correct defindex', () => {
|
||||
expect(getItemIndexByName(mockSchema, 'Flame Thrower')).toBe(208)
|
||||
expect(getItemIndexByName(mockSchema, 'Mann Co. Supply Crate Key')).toBe(5021)
|
||||
@@ -113,25 +132,12 @@ describe('Schema Service', () => {
|
||||
// Mock GM_fetch response
|
||||
const mockResponse = {
|
||||
ok: true,
|
||||
json: async () => [
|
||||
{
|
||||
defindex: 1,
|
||||
item_name: 'Test Item',
|
||||
item_slot: 'misc',
|
||||
attributes: [
|
||||
{ "name": "cannot trade", "class": "cannot_trade", "value": 1 }
|
||||
],
|
||||
capabilities: {}
|
||||
},
|
||||
{
|
||||
defindex: 208,
|
||||
item_name: 'Flame Thrower',
|
||||
item_slot: 'primary',
|
||||
capabilities: { can_killstreakify: true }
|
||||
}
|
||||
]
|
||||
json: async () => mockSchemaResponse
|
||||
};
|
||||
|
||||
// Mock Chrome runtime message
|
||||
(chrome.runtime.sendMessage as jest.Fn).mockImplementation(() => mockSchemaResponse);
|
||||
|
||||
// Mock GM_fetch
|
||||
globalThis.GM_fetch = mock(async () => mockResponse);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user