Skip to content

Commit d861377

Browse files
committed
Refactor mapClientID2NameSorted to process mixed arrays with keyword markers
1 parent ed0d5af commit d861377

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,15 @@ export function mapClientID2NameSorted(
220220
return [];
221221
}
222222

223-
// If any element in the array contains keyword markers, return the array as-is
224-
if (Array.isArray(enabledClients) && enabledClients.some((client) => hasKeywordMarkers(client))) {
225-
return enabledClients;
226-
}
223+
// Process each element: preserve keyword markers, convert client IDs to names
224+
const processedClients = enabledClients.map((client) => {
225+
if (hasKeywordMarkers(client)) {
226+
return client;
227+
}
228+
return convertClientIdToName(client, knownClients);
229+
});
227230

228-
return [
229-
...(enabledClients || []).map((clientId) => convertClientIdToName(clientId, knownClients)),
230-
].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
231+
return processedClients.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
231232
}
232233

233234
export function nomalizedYAMLPath(filePath: string): string[] {

test/tools/utils.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ describe('#mapClientID2NameSorted', () => {
121121
expect(result).to.deep.equal([]);
122122
});
123123

124-
it('should handle null/undefined enabled clients', () => {
125-
const result = mapClientID2NameSorted(null, mockClients);
126-
expect(result).to.deep.equal([]);
124+
it('should handle empty string enabled clients', () => {
125+
const result = mapClientID2NameSorted('', mockClients);
126+
expect(result).to.deep.equal('');
127127
});
128128

129129
it('should preserve keyword markers in arrays', () => {
130-
const enabledClientsWithKeywords = ['@@CLIENT_KEYWORD@@', 'client-a-id'];
130+
const enabledClientsWithKeywords = ['##CLIENT_KEYWORD##', 'client-a-id'];
131131
const result = mapClientID2NameSorted(enabledClientsWithKeywords, mockClients);
132-
// When an array contains keyword markers, the entire array should be returned as-is
133-
expect(result).to.deep.equal(enabledClientsWithKeywords);
132+
133+
const expectedClientsWithKeywords = ['##CLIENT_KEYWORD##', 'Client A'];
134+
expect(result).to.deep.equal(expectedClientsWithKeywords);
134135
});
135136
});

0 commit comments

Comments
 (0)