You've already forked tf2wikipricing
feat: add support for festive weapon variants
on schema update, festive variants are linked. on content injection, if if finds a festive variant, it adds price rows for Festive and Strange Festive.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test, mock } from "bun:test";
|
||||
import { ItemSchema, ItemSlot, getItemIndexByName, getTradableStatusByDefindex, getTradableStatusByName, prepareSchema } from '../src/content/schemaService'
|
||||
import { ItemSchema, ItemSlot, getItemIndexByName, getTradableStatusByDefindex, getTradableStatusByName, linkFestiveVariants, prepareSchema } from '../src/content/schemaService'
|
||||
|
||||
// Mock the storage and log functions
|
||||
mock.module('../src/content/storage', () => ({
|
||||
@@ -19,35 +19,48 @@ const mockSchema: ItemSchema = {
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: false,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: true
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
},
|
||||
'208': {
|
||||
name: 'Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: true,
|
||||
canKillstreakify: true
|
||||
canKillstreakify: true,
|
||||
festiveVariant: 659
|
||||
},
|
||||
'659': {
|
||||
name: 'Festive Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
},
|
||||
'5021': {
|
||||
name: 'Mann Co. Supply Crate Key',
|
||||
slot: ItemSlot.Tool,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: false
|
||||
canKillstreakify: false,
|
||||
festiveVariant: null
|
||||
},
|
||||
'15141': {
|
||||
name: 'Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: true
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
},
|
||||
'69420': {
|
||||
name: 'Non-Tradable Item',
|
||||
slot: ItemSlot.Misc,
|
||||
tradable: false,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: false
|
||||
canKillstreakify: false,
|
||||
festiveVariant: null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +130,75 @@ describe('Schema Service', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('linkFestiveVariants', () => {
|
||||
test('should link festive variants to their original counterparts', () => {
|
||||
const testSchema = {
|
||||
'21': { // Stock (should be ignored)
|
||||
name: 'Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: false,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: false,
|
||||
festiveVariant: null
|
||||
},
|
||||
'208': { // Original Flame Thrower
|
||||
name: 'Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: true,
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
},
|
||||
'659': { // Festive Flame Thrower (should be detected)
|
||||
name: 'Festive Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
},
|
||||
'15141': { // Decorated (should be ignored)
|
||||
name: 'Flame Thrower',
|
||||
slot: ItemSlot.Primary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: true,
|
||||
festiveVariant: null
|
||||
}
|
||||
};
|
||||
const mockResponseItems = [
|
||||
{ item_class: 'tf_weapon_flamethrower', defindex: 21, item_name: 'Flame Thrower' }, // Incorrect; stock
|
||||
{ item_class: 'tf_weapon_flamethrower', defindex: 208, item_name: 'Flame Thrower' }, // Original
|
||||
{ item_class: 'tf_weapon_flamethrower', defindex: 659, item_name: 'Festive Flame Thrower' }, // Festive
|
||||
{ item_class: 'tf_weapon_flamethrower', defindex: 15141, item_name: 'Flame Thrower' }, // Incorrect; decorated
|
||||
];
|
||||
linkFestiveVariants(mockResponseItems, testSchema)
|
||||
expect(testSchema['21'].festiveVariant).toBeNull()
|
||||
expect(testSchema['208'].festiveVariant).toBe(659)
|
||||
expect(testSchema['659'].festiveVariant).toBeNull();
|
||||
expect(testSchema['15141'].festiveVariant).toBeNull()
|
||||
})
|
||||
|
||||
test('should not link if no festive variant exists', () => {
|
||||
const testSchema = {
|
||||
'163': {
|
||||
name: 'Crit-a-Cola',
|
||||
slot: ItemSlot.Secondary,
|
||||
tradable: true,
|
||||
hasAustraliumVariant: false,
|
||||
canKillstreakify: false,
|
||||
festiveVariant: null
|
||||
}
|
||||
};
|
||||
|
||||
const mockResponseItems = [
|
||||
{ item_class: 'tf_weapon_lunchbox_drink', defindex: 163, item_name: 'Crit-a-Cola' }
|
||||
];
|
||||
|
||||
linkFestiveVariants(mockResponseItems, testSchema);
|
||||
|
||||
expect(testSchema['163'].festiveVariant).toBeNull();
|
||||
});
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user