1+ import {
2+ CONFIG ,
3+ DICE_TYPES ,
4+ CURRENCY_TYPES ,
5+ CURRENCY_ABBREVIATIONS ,
6+ CURRENCY_TO_GOLD_CONVERSION ,
7+ DEFAULT_CONVERSION_FEE ,
8+ ERROR_MESSAGES
9+ } from './constants.js' ;
10+
11+ describe ( 'constants' , ( ) => {
12+ describe ( 'CONFIG' , ( ) => {
13+ test ( 'should have expected numeric values' , ( ) => {
14+ expect ( CONFIG . MAX_DICE_QUANTITY ) . toBe ( 100 ) ;
15+ expect ( CONFIG . MAX_DICE_SIDES ) . toBe ( 100 ) ;
16+ expect ( CONFIG . MAX_ITEM_NAME_LENGTH ) . toBe ( 100 ) ;
17+ expect ( CONFIG . MIN_SEARCH_TERM_LENGTH ) . toBe ( 2 ) ;
18+ expect ( CONFIG . SIMILARITY_THRESHOLD ) . toBe ( 0.5 ) ;
19+ expect ( CONFIG . DISCORD_MESSAGE_LIMIT ) . toBe ( 2000 ) ;
20+ expect ( CONFIG . TRACKER_MESSAGE_LIMIT ) . toBe ( 1900 ) ;
21+ expect ( CONFIG . CHUNK_SIZE_CALCULATION_THRESHOLD ) . toBe ( 100000 ) ;
22+ } ) ;
23+
24+ test ( 'should have collection names object' , ( ) => {
25+ expect ( CONFIG . COLLECTION_NAMES ) . toEqual ( {
26+ TRACKERS : "trackers" ,
27+ TRACKER_AUDIT_LOG : "tracker_audit_log" ,
28+ BANK : "bank" ,
29+ BANK_AUDIT_LOG : "bank_audit_log" ,
30+ BANK_SETTINGS : "bank_settings" ,
31+ } ) ;
32+ } ) ;
33+ } ) ;
34+
35+ describe ( 'DICE_TYPES' , ( ) => {
36+ test ( 'should contain expected dice types' , ( ) => {
37+ expect ( DICE_TYPES ) . toEqual ( [ 4 , 6 , 8 , 10 , 12 , 20 , 100 ] ) ;
38+ } ) ;
39+
40+ test ( 'should be an array of numbers' , ( ) => {
41+ DICE_TYPES . forEach ( type => {
42+ expect ( typeof type ) . toBe ( 'number' ) ;
43+ } ) ;
44+ } ) ;
45+ } ) ;
46+
47+ describe ( 'CURRENCY_TYPES' , ( ) => {
48+ test ( 'should contain expected currency types' , ( ) => {
49+ expect ( CURRENCY_TYPES ) . toEqual ( [ "platinum" , "gold" , "silver" , "electrum" , "copper" ] ) ;
50+ } ) ;
51+
52+ test ( 'should be an array of strings' , ( ) => {
53+ CURRENCY_TYPES . forEach ( type => {
54+ expect ( typeof type ) . toBe ( 'string' ) ;
55+ } ) ;
56+ } ) ;
57+ } ) ;
58+
59+ describe ( 'CURRENCY_ABBREVIATIONS' , ( ) => {
60+ test ( 'should have abbreviations for all currency types' , ( ) => {
61+ CURRENCY_TYPES . forEach ( currency => {
62+ expect ( CURRENCY_ABBREVIATIONS [ currency ] ) . toBeDefined ( ) ;
63+ expect ( typeof CURRENCY_ABBREVIATIONS [ currency ] ) . toBe ( 'string' ) ;
64+ } ) ;
65+ } ) ;
66+
67+ test ( 'should have expected abbreviations' , ( ) => {
68+ expect ( CURRENCY_ABBREVIATIONS . platinum ) . toBe ( 'pp' ) ;
69+ expect ( CURRENCY_ABBREVIATIONS . gold ) . toBe ( 'gp' ) ;
70+ expect ( CURRENCY_ABBREVIATIONS . silver ) . toBe ( 'sp' ) ;
71+ expect ( CURRENCY_ABBREVIATIONS . electrum ) . toBe ( 'ep' ) ;
72+ expect ( CURRENCY_ABBREVIATIONS . copper ) . toBe ( 'cp' ) ;
73+ } ) ;
74+ } ) ;
75+
76+ describe ( 'CURRENCY_TO_GOLD_CONVERSION' , ( ) => {
77+ test ( 'should have conversion rates for all currency types' , ( ) => {
78+ CURRENCY_TYPES . forEach ( currency => {
79+ expect ( CURRENCY_TO_GOLD_CONVERSION [ currency ] ) . toBeDefined ( ) ;
80+ expect ( typeof CURRENCY_TO_GOLD_CONVERSION [ currency ] ) . toBe ( 'number' ) ;
81+ } ) ;
82+ } ) ;
83+
84+ test ( 'should have expected conversion rates' , ( ) => {
85+ expect ( CURRENCY_TO_GOLD_CONVERSION . platinum ) . toBe ( 10 ) ;
86+ expect ( CURRENCY_TO_GOLD_CONVERSION . gold ) . toBe ( 1 ) ;
87+ expect ( CURRENCY_TO_GOLD_CONVERSION . electrum ) . toBe ( 0.5 ) ;
88+ expect ( CURRENCY_TO_GOLD_CONVERSION . silver ) . toBe ( 0.1 ) ;
89+ expect ( CURRENCY_TO_GOLD_CONVERSION . copper ) . toBe ( 0.01 ) ;
90+ } ) ;
91+ } ) ;
92+
93+ describe ( 'DEFAULT_CONVERSION_FEE' , ( ) => {
94+ test ( 'should be a number' , ( ) => {
95+ expect ( typeof DEFAULT_CONVERSION_FEE ) . toBe ( 'number' ) ;
96+ } ) ;
97+
98+ test ( 'should be 10% (0.1)' , ( ) => {
99+ expect ( DEFAULT_CONVERSION_FEE ) . toBe ( 0.1 ) ;
100+ } ) ;
101+ } ) ;
102+
103+ describe ( 'ERROR_MESSAGES' , ( ) => {
104+ test ( 'should have all expected error message keys' , ( ) => {
105+ const expectedKeys = [
106+ 'INVALID_QUANTITY' ,
107+ 'ITEM_NAME_TOO_LONG' ,
108+ 'ITEM_NOT_FOUND' ,
109+ 'TRACKER_EMPTY' ,
110+ 'SEARCH_TERM_TOO_SHORT' ,
111+ 'NO_PERMISSION' ,
112+ 'MAX_DICE_EXCEEDED' ,
113+ 'MAX_SIDES_EXCEEDED' ,
114+ 'INVALID_CURRENCY' ,
115+ 'BANK_EMPTY' ,
116+ 'INVALID_FEE_RATE' ,
117+ 'SAME_CURRENCY_CONVERSION' ,
118+ 'INSUFFICIENT_CONVERSION_BALANCE' ,
119+ 'GENERIC_ERROR' ,
120+ 'DATABASE_ERROR'
121+ ] ;
122+
123+ expectedKeys . forEach ( key => {
124+ expect ( ERROR_MESSAGES [ key ] ) . toBeDefined ( ) ;
125+ expect ( typeof ERROR_MESSAGES [ key ] ) . toBe ( 'string' ) ;
126+ } ) ;
127+ } ) ;
128+
129+ test ( 'should have non-empty error messages' , ( ) => {
130+ Object . values ( ERROR_MESSAGES ) . forEach ( message => {
131+ expect ( message . length ) . toBeGreaterThan ( 0 ) ;
132+ } ) ;
133+ } ) ;
134+ } ) ;
135+ } ) ;
0 commit comments