選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

44 行
2.2KB

  1. var fs = new ActiveXObject("Scripting.FileSystemObject");
  2. var root = fs.GetParentFolderName(fs.GetParentFolderName(WScript.ScriptFullName));
  3. eval(fs.OpenTextFile(fs.BuildPath(root, "src\\contacts.js"), 1).ReadAll());
  4. function assert(condition, message) {
  5. if (!condition) throw new Error(message);
  6. }
  7. try {
  8. var csv = "\ufeffemail,business_name,source_reference,acquired_at\r\n" +
  9. 'one@example.com,"Acme, Inc.",https://example.com/acme,2026-10-21\r\n' +
  10. 'ONE@example.com,Duplicate,https://example.com/acme,\r\n' +
  11. 'blocked@example.com,Blocked,https://example.com/blocked,\r\n' +
  12. 'bad address,Bad,https://example.com/bad,\r\n' +
  13. 'two@example.com,"Two\nLines",https://example.com/two,\r\n';
  14. var result = MassMailerContacts.preview(csv, "", {}, { "blocked@example.com": true });
  15. assert(result.accepted.length === 2, "Expected two accepted rows");
  16. assert(result.rejected.length === 3, "Expected three rejected rows");
  17. assert(result.accepted[0].businessName === "Acme, Inc.", "Quoted comma lost");
  18. assert(result.accepted[1].businessName === "Two\nLines", "Quoted newline lost");
  19. assert(result.rejected[0].reason === "Duplicate in CSV", "Duplicate reason wrong");
  20. assert(result.rejected[1].reason === "Suppressed address", "Suppression reason wrong");
  21. assert(result.rejected[2].reason === "Invalid email", "Invalid email reason wrong");
  22. var fallback = MassMailerContacts.preview("email\na@example.com", "public directory", {}, {});
  23. assert(fallback.accepted.length === 1, "Fallback source should allow email-only CSV");
  24. assert(fallback.accepted[0].source === "public directory", "Fallback source missing");
  25. var missingSource = MassMailerContacts.preview("email\na@example.com", "", {}, {});
  26. assert(missingSource.rejected[0].reason === "Missing source reference", "Missing source not flagged");
  27. assert(!MassMailerContacts.isoDate("2026-02-30"), "Invalid date accepted");
  28. try {
  29. MassMailerContacts.parseCsv('email\n"unclosed');
  30. throw new Error("Unclosed CSV quote was accepted");
  31. } catch (error) {
  32. if (error.message === "Unclosed CSV quote was accepted") throw error;
  33. }
  34. WScript.Echo("Contact parser tests passed");
  35. } catch (error) {
  36. WScript.Echo("FAIL: " + error.message);
  37. WScript.Quit(1);
  38. }

Powered by TurnKey Linux.