From 9a8ce2431322a620771c152bfb9360be293a66e0 Mon Sep 17 00:00:00 2001 From: xenticore Date: Mon, 7 Apr 2025 15:40:44 -0400 Subject: [PATCH] test: add botkiller detection tests --- __tests__/schema.test.ts | 160 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 148 insertions(+), 12 deletions(-) diff --git a/__tests__/schema.test.ts b/__tests__/schema.test.ts index d5b9853..bd1d516 100644 --- a/__tests__/schema.test.ts +++ b/__tests__/schema.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test, mock } from "bun:test"; -import { ItemSchema, ItemSlot, getItemIndexByName, getTradableStatusByDefindex, getTradableStatusByName, linkFestiveVariants, prepareSchema } from '../src/content/schemaService' +import { ItemSchema, ItemSlot, getItemIndexByName, getTradableStatusByDefindex, getTradableStatusByName, linkBotkillerVariants, linkFestiveVariants, prepareSchema } from '../src/content/schemaService' // Mock the storage and log functions mock.module('../src/content/storage', () => ({ @@ -20,7 +20,8 @@ const mockSchema: ItemSchema = { tradable: false, hasAustraliumVariant: false, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '208': { name: 'Flame Thrower', @@ -28,7 +29,8 @@ const mockSchema: ItemSchema = { tradable: true, hasAustraliumVariant: true, canKillstreakify: true, - festiveVariant: 659 + festiveVariant: 659, + botkillerVariants: [798, 807] }, '659': { name: 'Festive Flame Thrower', @@ -36,7 +38,26 @@ const mockSchema: ItemSchema = { tradable: true, hasAustraliumVariant: false, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null + }, + '798': { + name: 'Silver Botkiller Flame Thrower Mk.I', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: false, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null + }, + '807': { + name: 'Gold Botkiller Flame Thrower Mk.I', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: false, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null }, '5021': { name: 'Mann Co. Supply Crate Key', @@ -44,7 +65,8 @@ const mockSchema: ItemSchema = { tradable: true, hasAustraliumVariant: false, canKillstreakify: false, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '15141': { name: 'Flame Thrower', @@ -52,7 +74,8 @@ const mockSchema: ItemSchema = { tradable: true, hasAustraliumVariant: false, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '69420': { name: 'Non-Tradable Item', @@ -60,7 +83,8 @@ const mockSchema: ItemSchema = { tradable: false, hasAustraliumVariant: false, canKillstreakify: false, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null } } @@ -140,7 +164,8 @@ describe('Schema Service', () => { tradable: false, hasAustraliumVariant: false, canKillstreakify: false, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '208': { // Original Flame Thrower name: 'Flame Thrower', @@ -148,7 +173,8 @@ describe('Schema Service', () => { tradable: true, hasAustraliumVariant: true, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '659': { // Festive Flame Thrower (should be detected) name: 'Festive Flame Thrower', @@ -156,7 +182,8 @@ describe('Schema Service', () => { tradable: true, hasAustraliumVariant: false, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null }, '15141': { // Decorated (should be ignored) name: 'Flame Thrower', @@ -164,7 +191,8 @@ describe('Schema Service', () => { tradable: true, hasAustraliumVariant: false, canKillstreakify: true, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null } }; const mockResponseItems = [ @@ -188,7 +216,8 @@ describe('Schema Service', () => { tradable: true, hasAustraliumVariant: false, canKillstreakify: false, - festiveVariant: null + festiveVariant: null, + botkillerVariants: null } }; @@ -201,4 +230,111 @@ describe('Schema Service', () => { expect(testSchema['163'].festiveVariant).toBeNull(); }); }); + + describe('linkBotkillerVariants', () => { + test('should link botkiller variants to their original counterparts', () => { + const testSchema = { + '21': { // Original Rocket Launcher + name: 'Flame Thrower', + slot: ItemSlot.Primary, + tradable: false, + hasAustraliumVariant: false, + canKillstreakify: false, + festiveVariant: null, + botkillerVariants: null + }, + '208': { // Original Flame Thrower + name: 'Flame Thrower', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: true, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null + }, + '798': { + name: 'Silver Botkiller Flame Thrower Mk. I', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: false, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null + }, + '807': { + name: 'Gold Botkiller Flame Thrower Mk. I', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: false, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null + }, + '15141': { // Decorated (should be ignored) + name: 'Flame Thrower', + slot: ItemSlot.Primary, + tradable: true, + hasAustraliumVariant: false, + canKillstreakify: true, + festiveVariant: null, + botkillerVariants: null + } + }; + const mockResponseItems = [ + { item_class: 'tf_weapon_flamethrower', defindex: 21, item_name: 'Flame Thrower', item_type_name: 'Flame Thrower' + }, // Incorrect; stock + { + item_class: 'tf_weapon_flamethrower', + defindex: 208, + item_name: 'Flame Thrower', + item_type_name: 'Flame Thrower' + }, + { + item_class: 'tf_weapon_flamethrower', + defindex: 798, + item_name: 'Silver Botkiller Flame Thrower Mk.I', + item_type_name: 'Flame Thrower' + }, + { + item_class: 'tf_weapon_flamethrower', + defindex: 807, + item_name: 'Gold Botkiller Flame Thrower Mk.I', + item_type_name: 'Flame Thrower' + }, + { item_class: 'tf_weapon_flamethrower', defindex: 15141, item_name: 'Flame Thrower', item_type_name: 'Flame Thrower' }, // Incorrect; decorated + ]; + linkBotkillerVariants(mockResponseItems, testSchema); + expect(testSchema['21'].botkillerVariants).toBeNull() + expect(testSchema['208'].botkillerVariants).toEqual([798, 807]); + expect(testSchema['798'].botkillerVariants).toBeNull(); + expect(testSchema['807'].botkillerVariants).toBeNull(); + expect(testSchema['15141'].botkillerVariants).toBeNull() + }); + + test('should not link if no botkiller variants exist', () => { + const testSchema = { + '163': { // Crit-a-Cola + name: 'Crit-a-Cola', + slot: ItemSlot.Secondary, + tradable: true, + hasAustraliumVariant: false, + festiveVariant: null, + canKillstreakify: false, + botkillerVariants: null, + } + }; + + const mockResponseItems = [ + { + item_class: 'tf_weapon_lunchbox_drink', + defindex: 163, + item_name: 'Crit-a-Cola', + item_type_name: 'Lunch Box', + } + ]; + + linkBotkillerVariants(mockResponseItems, testSchema); + expect(testSchema['163'].botkillerVariants).toBeNull(); + }); + }) }) \ No newline at end of file