|
1 |
| -import { describe, it, expect, afterAll, beforeAll } from 'vitest'; |
| 1 | +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
2 | 2 | import { parseFilter } from '../../Filter';
|
3 |
| -import { Search } from '../../Search'; |
4 | 3 | 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'; |
6 | 8 |
|
7 |
| -describe('Search Tests', {concurrent: true}, () => { |
| 9 | +describe('Search Tests', { concurrent: true }, () => { |
8 | 10 | let connection: IBMi
|
9 | 11 | beforeAll(async () => {
|
10 | 12 | connection = await newConnection();
|
@@ -53,5 +55,46 @@ describe('Search Tests', {concurrent: true}, () => {
|
53 | 55 | expect(result.hits.length).toBe(6);
|
54 | 56 | expect(checkNames(result.hits.map(hit => hit.path.split("/").at(-1)!))).toBe(true);
|
55 | 57 | 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 | + }); |
57 | 100 | });
|
0 commit comments