@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
3
3
import * as config from "./config" ;
4
4
import { calculateCFsToManage , loadCustomFormatDefinitions , loadLocalCfs , mergeCfSources } from "./custom-formats" ;
5
5
import { loadTrashCFs } from "./trash-guide" ;
6
- import { CFProcessing } from "./types/common.types" ;
6
+ import { CFIDToConfigGroup } from "./types/common.types" ;
7
7
import { ConfigCustomFormatList } from "./types/config.types" ;
8
8
import { TrashCF } from "./types/trashguide.types" ;
9
9
import * as util from "./util" ;
@@ -43,15 +43,15 @@ describe("CustomFormats", () => {
43
43
vi . spyOn ( config , "getConfig" ) . mockReturnValue ( { localCustomFormatsPath : undefined } ) ;
44
44
45
45
const result = await loadLocalCfs ( ) ;
46
- expect ( result ) . toBeNull ( ) ;
46
+ expect ( result . size ) . toBe ( 0 ) ;
47
47
} ) ;
48
48
49
49
it ( "should return null when configured path doesn't exist" , async ( ) => {
50
50
vi . spyOn ( config , "getConfig" ) . mockReturnValue ( { localCustomFormatsPath : "/fake/path" } ) ;
51
51
vi . spyOn ( fs , "existsSync" ) . mockReturnValue ( false ) ;
52
52
53
53
const result = await loadLocalCfs ( ) ;
54
- expect ( result ) . toBeNull ( ) ;
54
+ expect ( result . size ) . toBe ( 0 ) ;
55
55
} ) ;
56
56
57
57
it ( "should load and process JSON files from configured path" , async ( ) => {
@@ -65,22 +65,16 @@ describe("CustomFormats", () => {
65
65
66
66
const result = await loadLocalCfs ( ) ;
67
67
expect ( result ) . not . toBeNull ( ) ;
68
- expect ( result ! . carrIdMapping . size ) . toBe ( 1 ) ;
69
- expect ( result ! . carrIdMapping . get ( customCF . trash_id ) ) . not . toBeNull ( ) ;
68
+ expect ( result . size ) . toBe ( 1 ) ;
69
+ expect ( result . get ( customCF . trash_id ) ) . not . toBeNull ( ) ;
70
70
} ) ;
71
71
} ) ;
72
72
73
73
describe ( "mergeCfSources" , ( ) => {
74
74
it ( "should merge multiple CF sources correctly" , ( ) => {
75
- const source1 : CFProcessing = {
76
- carrIdMapping : new Map ( [ [ "id1" , { carrConfig : { configarr_id : "id1" , name : "CF1" } , requestConfig : { } } ] ] ) ,
77
- cfNameToCarrConfig : new Map ( [ [ "CF1" , { configarr_id : "id1" , name : "CF1" } ] ] ) ,
78
- } ;
75
+ const source1 : CFIDToConfigGroup = new Map ( [ [ "id1" , { carrConfig : { configarr_id : "id1" , name : "CF1" } , requestConfig : { } } ] ] ) ;
79
76
80
- const source2 : CFProcessing = {
81
- carrIdMapping : new Map ( [ [ "id2" , { carrConfig : { configarr_id : "id2" , name : "CF2" } , requestConfig : { } } ] ] ) ,
82
- cfNameToCarrConfig : new Map ( [ [ "CF2" , { configarr_id : "id2" , name : "CF2" } ] ] ) ,
83
- } ;
77
+ const source2 : CFIDToConfigGroup = new Map ( [ [ "id2" , { carrConfig : { configarr_id : "id2" , name : "CF2" } , requestConfig : { } } ] ] ) ;
84
78
85
79
const result = mergeCfSources ( new Set ( [ "id1" , "id2" ] ) , [ source1 , source2 , null ] ) ;
86
80
@@ -112,10 +106,9 @@ describe("CustomFormats", () => {
112
106
113
107
describe ( "loadCustomFormatDefinitions" , ( ) => {
114
108
it ( "should load and merge (trash CFDs" , async ( ) => {
115
- const mockTrashCFs : CFProcessing = {
116
- carrIdMapping : new Map ( [ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ] ) ,
117
- cfNameToCarrConfig : new Map ( ) ,
118
- } ;
109
+ const mockTrashCFs : CFIDToConfigGroup = new Map ( [
110
+ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ,
111
+ ] ) ;
119
112
120
113
vi . mock ( "./trash-guide" ) ;
121
114
vi . mocked ( loadTrashCFs ) . mockResolvedValue ( mockTrashCFs ) ;
@@ -128,10 +121,9 @@ describe("CustomFormats", () => {
128
121
} ) ;
129
122
130
123
it ( "should load and merge (additional CFDs)" , async ( ) => {
131
- const mockTrashCFs : CFProcessing = {
132
- carrIdMapping : new Map ( [ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ] ) ,
133
- cfNameToCarrConfig : new Map ( ) ,
134
- } ;
124
+ const mockTrashCFs : CFIDToConfigGroup = new Map ( [
125
+ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ,
126
+ ] ) ;
135
127
136
128
vi . mock ( "./trash-guide" ) ;
137
129
vi . mocked ( loadTrashCFs ) . mockResolvedValue ( mockTrashCFs ) ;
@@ -144,10 +136,9 @@ describe("CustomFormats", () => {
144
136
} ) ;
145
137
146
138
it ( "should ignore not managed CFs" , async ( ) => {
147
- const mockTrashCFs : CFProcessing = {
148
- carrIdMapping : new Map ( [ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ] ) ,
149
- cfNameToCarrConfig : new Map ( ) ,
150
- } ;
139
+ const mockTrashCFs : CFIDToConfigGroup = new Map ( [
140
+ [ "trash1" , { carrConfig : { configarr_id : "trash1" , name : "trash1" } , requestConfig : { } } ] ,
141
+ ] ) ;
151
142
152
143
vi . mock ( "./trash-guide" ) ;
153
144
vi . mocked ( loadTrashCFs ) . mockResolvedValue ( mockTrashCFs ) ;
0 commit comments