This repository was archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebmention-verifier.test.js
121 lines (100 loc) · 5.55 KB
/
webmention-verifier.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var assert = require('assert');
const verifier = require('../lib/webmention-verifier');
const fs = require('fs');
const nock = require('nock');
describe('webmention-verifier', function() {
it('should return status code 400 if the source URL is not valid', async function() {
const expected={statusCode: 400, body: "Source is not a valid URL", webmention: false};
const actual = await verifier('Not a url','https://www.duckduckgo.com');
assert.deepEqual(actual,expected);
});
it('should return status code 400 if the target URL is not valid', async function() {
const expected={statusCode: 400, body: "Target is not a valid URL", webmention: false};
const actual = await verifier('https://www.duckduckgo.com','Not a url');
assert.deepEqual(actual,expected);
});
it('should return status code 400 if the target URL and source URL are the same', async function() {
const expected={statusCode: 400,body: "Source and target are same URL", webmention: false};
const actual = await verifier('https://www.duckduckgo.com','https://www.duckduckgo.com');
assert.deepEqual(actual,expected);
});
it('should return status code 400 if the target domain is not accepted by this receiver', async function() {
const expected={statusCode: 400,body: "Target domain is not accepted by this server", webmention: false};
const actual = await verifier('https://www.duckduckgo.com','https://www.google.com',['www.duckduckgo.com']);
assert.deepEqual(actual,expected);
});
it('should return status code 400 if the source url cannot be fetched (does not exist)', async function() {
const expected={statusCode: 400,body: "Source url does not exist", webmention: false};
const actual = await verifier('https://www.thisisavalidurlasdfasdfasd21f25sa1d56fasd.com','https://www.duckduckgo.com');
assert.deepEqual(actual,expected);
});
it('should return status code 400 if source does not mention target', async function() {
const data = fs.readFileSync('./test/data/webmention-verifier-multiple-h-entry.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.notmentioned.com');
assert.equal(actual.statusCode,400);
});
it('should find in-reply-to', async function() {
const data = fs.readFileSync('./test/data/webmention-verifier-single-h-entry.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention["in-reply-to"],"https://www.duckduckgo.com");
assert.equal(actual.webmention["wm-property"],"in-reply-to");
});
it('should find in-reply-to with multiple h-entries', async function() {
const data = fs.readFileSync('./test/data/webmention-verifier-multiple-h-entry.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention["in-reply-to"],"https://www.duckduckgo.com");
assert.equal(actual.webmention["wm-property"],"in-reply-to");
});
it('should find author as William Shakespeare with only p-author', async function() {
const data = fs.readFileSync('./test/data/webmention-verifier-single-h-entry.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention.author,"William Shakespeare");
});
it('should find author as Homer from embedded h-card', async function() {
const data = fs.readFileSync('./test/data/author-with-embedded-h-card.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention.author.name,"Homer");
});
it('should find author as Patañjali from embedded h-card, not from rel-author page', async function() {
const data = fs.readFileSync('./test/data/author-with-embedded-h-card-and-rel-author.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention.author.name,"Patañjali");
});
it('should find author as Virginia Woolf from rel-author page', async function() {
const data = fs.readFileSync('./test/data/only-rel-author-link.html');
const data2 = fs.readFileSync('./test/data/virginia-woolf.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data)
.get('/virginia-woolf.html')
.reply(200,data2);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention.author.name,"Virginia Woolf");
});
it('should find webmention with no microformats', async function() {
const data = fs.readFileSync('./test/data/no-microformats.html');
const scope = nock('https://www.example.com')
.get('/post.html')
.reply(200, data);
const actual = await verifier('https://www.example.com/post.html','https://www.duckduckgo.com');
assert.equal(actual.webmention.hasOwnProperty("mention-of"),true);
});
});