|
- var fs = new ActiveXObject("Scripting.FileSystemObject");
- var root = fs.GetParentFolderName(fs.GetParentFolderName(WScript.ScriptFullName));
- eval(fs.OpenTextFile(fs.BuildPath(root, "src\\contacts.js"), 1).ReadAll());
-
- function assert(condition, message) {
- if (!condition) throw new Error(message);
- }
-
- try {
- var csv = "\ufeffemail,business_name,source_reference,acquired_at\r\n" +
- 'one@example.com,"Acme, Inc.",https://example.com/acme,2026-10-21\r\n' +
- 'ONE@example.com,Duplicate,https://example.com/acme,\r\n' +
- 'blocked@example.com,Blocked,https://example.com/blocked,\r\n' +
- 'bad address,Bad,https://example.com/bad,\r\n' +
- 'two@example.com,"Two\nLines",https://example.com/two,\r\n';
- var result = MassMailerContacts.preview(csv, "", {}, { "blocked@example.com": true });
- assert(result.accepted.length === 2, "Expected two accepted rows");
- assert(result.rejected.length === 3, "Expected three rejected rows");
- assert(result.accepted[0].businessName === "Acme, Inc.", "Quoted comma lost");
- assert(result.accepted[1].businessName === "Two\nLines", "Quoted newline lost");
- assert(result.rejected[0].reason === "Duplicate in CSV", "Duplicate reason wrong");
- assert(result.rejected[1].reason === "Suppressed address", "Suppression reason wrong");
- assert(result.rejected[2].reason === "Invalid email", "Invalid email reason wrong");
-
- var fallback = MassMailerContacts.preview("email\na@example.com", "public directory", {}, {});
- assert(fallback.accepted.length === 1, "Fallback source should allow email-only CSV");
- assert(fallback.accepted[0].source === "public directory", "Fallback source missing");
-
- var missingSource = MassMailerContacts.preview("email\na@example.com", "", {}, {});
- assert(missingSource.rejected[0].reason === "Missing source reference", "Missing source not flagged");
-
- assert(!MassMailerContacts.isoDate("2026-02-30"), "Invalid date accepted");
- try {
- MassMailerContacts.parseCsv('email\n"unclosed');
- throw new Error("Unclosed CSV quote was accepted");
- } catch (error) {
- if (error.message === "Unclosed CSV quote was accepted") throw error;
- }
- WScript.Echo("Contact parser tests passed");
- } catch (error) {
- WScript.Echo("FAIL: " + error.message);
- WScript.Quit(1);
- }
|