|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { PostType, POST_FAILURE_REASONS } from "../../types/jobs-moderation"; |
| 3 | +import { links } from "./validate"; |
| 4 | + |
| 5 | +const makePost = (type: PostType, description: string) => [ |
| 6 | + { tags: [type], description }, |
| 7 | +]; |
| 8 | + |
| 9 | +describe("links", () => { |
| 10 | + it("requires links", () => { |
| 11 | + expect( |
| 12 | + links( |
| 13 | + makePost( |
| 14 | + PostType.hiring, |
| 15 | + "Hiring for some role and stuff\nDM me to apply", |
| 16 | + ), |
| 17 | + undefined, |
| 18 | + ), |
| 19 | + ).toContainEqual({ type: POST_FAILURE_REASONS.linkRequired }); |
| 20 | + expect( |
| 21 | + links( |
| 22 | + makePost( |
| 23 | + PostType.hiring, |
| 24 | + "Hiring for some role and stuff\nDM me to apply\nhttps://example.com", |
| 25 | + ), |
| 26 | + undefined, |
| 27 | + ), |
| 28 | + ).toHaveLength(0); |
| 29 | + expect( |
| 30 | + links( |
| 31 | + makePost(PostType.forHire, "advertising my own skills for hire"), |
| 32 | + undefined, |
| 33 | + ), |
| 34 | + ).toHaveLength(0); |
| 35 | + }); |
| 36 | + it("doesn't choke on weird urls", () => { |
| 37 | + const urls = [ |
| 38 | + "https://www.example.com", |
| 39 | + "https://subdomain.example.com", |
| 40 | + "https://www.sub.example.com", |
| 41 | + "https://www.example.com/path/to/page", |
| 42 | + "https://www.example.com/?query=param", |
| 43 | + "https://www.example.com/path/to/page?query=param", |
| 44 | + "https://www.example.com/#section", |
| 45 | + "https://www.example.com/path/to/page#section", |
| 46 | + "https://www.example.com/path/to/page?query=param#section", |
| 47 | + "https://xn--bcher-kva.example/", |
| 48 | + "https://192.168.0.1", |
| 49 | + "https://[2001:db8::ff00:42:8329]", |
| 50 | + "https://www.example.co.uk", |
| 51 | + "https://www.example.travel", |
| 52 | + "https://www.example.com:8080", |
| 53 | + "https://www.example.com:8443", |
| 54 | + "https://www.example.com/images/pic.jpg", |
| 55 | + "https://www.example.com/files/document.pdf", |
| 56 | + "https://www.example.com/path%20with%20spaces", |
| 57 | + ]; |
| 58 | + expect.assertions(urls.length); |
| 59 | + urls.forEach((url) => { |
| 60 | + expect( |
| 61 | + links( |
| 62 | + makePost( |
| 63 | + PostType.hiring, |
| 64 | + `Hiring for some role and stuff\nDM me to apply\n${url}`, |
| 65 | + ), |
| 66 | + undefined, |
| 67 | + ), |
| 68 | + ).toHaveLength(0); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments