Skip to content

Commit 864cea3

Browse files
committed
Added test for searching in members with a . in their name
Signed-off-by: Seb Julliand <[email protected]>
1 parent e1ea4e4 commit 864cea3

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

src/api/tests/suites/search.test.ts

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { describe, it, expect, afterAll, beforeAll } from 'vitest';
1+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
22
import { parseFilter } from '../../Filter';
3-
import { Search } from '../../Search';
43
import IBMi from '../../IBMi';
5-
import { newConnection, disposeConnection, CONNECTION_TIMEOUT } from '../connection';
4+
import { Search } from '../../Search';
5+
import { Tools } from '../../Tools';
6+
import { SearchResults } from '../../types';
7+
import { CONNECTION_TIMEOUT, disposeConnection, newConnection } from '../connection';
68

7-
describe('Search Tests', {concurrent: true}, () => {
9+
describe('Search Tests', { concurrent: true }, () => {
810
let connection: IBMi
911
beforeAll(async () => {
1012
connection = await newConnection();
@@ -53,5 +55,46 @@ describe('Search Tests', {concurrent: true}, () => {
5355
expect(result.hits.length).toBe(6);
5456
expect(checkNames(result.hits.map(hit => hit.path.split("/").at(-1)!))).toBe(true);
5557
expect(result.hits.every(hit => !hit.path.endsWith(`MBR`))).toBe(true);
56-
});
58+
}),
59+
60+
it('Member with `.` in name search', async () => {
61+
const library = connection.getConfig().tempLibrary;
62+
const file = `ZZ${Tools.makeid(6)}`;
63+
const crtsrcpf = await connection.runCommand({ command: `CRTSRCPF FILE(${library}/${file}) RCDLEN(112)`, noLibList: true });
64+
if (crtsrcpf.code !== 0) {
65+
throw new Error(`Failed to create test source file: ${crtsrcpf.stderr}`);
66+
}
67+
try {
68+
const members = [
69+
{ name: "AN.RPGLE", type: "RPGLE", content: ["Some random text", "nobody will read", "but that's for testing"] },
70+
{ name: "A.CLLE", type: "CLLE", content: ["More random text", "testing is fun", "or so they say"] },
71+
{ name: "A.CMD", type: "CMD", content: ["This is not valid for a command", "this is for a test", "so I guess it's fine"] }
72+
];
73+
74+
for (const member of members) {
75+
const addpfm = await connection.runCommand({ command: `ADDPFM FILE(${library}/${file}) MBR(${member.name}) SRCTYPE(${member.type})`, noLibList: true });
76+
if (addpfm.code !== 0) {
77+
throw new Error(`Failed to add test member: ${addpfm.stderr}`);
78+
}
79+
await connection.getContent().uploadMemberContent(library, file, member.name, member.content.join("\n"));
80+
}
81+
82+
const hasMember = (results: SearchResults, member: string) => results.hits.map(hit => hit.path.split('/').pop()).includes(member);
83+
84+
const searchTest = await Search.searchMembers(connection, library, file, "test", '*');
85+
expect(searchTest.hits.length).toBe(3);
86+
expect(hasMember(searchTest, "AN.RPGLE")).toBe(true);
87+
expect(hasMember(searchTest, "A.CLLE")).toBe(true);
88+
expect(hasMember(searchTest, "A.CMD")).toBe(true);
89+
90+
const searchTesting = await Search.searchMembers(connection, library, file, "testing", '*');
91+
expect(searchTesting.hits.length).toBe(2);
92+
expect(hasMember(searchTesting, "AN.RPGLE")).toBe(true);
93+
expect(hasMember(searchTesting, "A.CLLE")).toBe(true);
94+
expect(hasMember(searchTesting, "A.CMD")).toBe(false);
95+
}
96+
finally {
97+
await connection.runCommand({ command: `DLTF FILE(${library} / ${file})`, noLibList: true });
98+
}
99+
});
57100
});

0 commit comments

Comments
 (0)