forked from itteco/iframely
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_plugins.js
91 lines (76 loc) · 2.79 KB
/
custom_plugins.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
'use strict';
import request from 'supertest';
import ServerMock from 'mock-http-server';
import chai from 'chai';
import app from '../app.js';
describe('custom plugins', function() {
var BASE_IFRAMELY_SERVER_URL = 'http://localhost:' + process.env.PORT;
var TARGET_MOCKED_SERVER_PORT = 9000;
var TARGET_MOCKED_SERVER_BASEURL = 'http://127.0.0.1:' + TARGET_MOCKED_SERVER_PORT;
var targetMockedServer = new ServerMock({ host: '127.0.0.1', port: TARGET_MOCKED_SERVER_PORT });
var server;
beforeEach(function(done) {
server = app.listen(process.env.PORT, function() {
targetMockedServer.start(done);
});
});
afterEach(function(done) {
server.close(function() {
targetMockedServer.stop(done);
});
});
it('should use a custom plugin if defined', function(done) {
targetMockedServer.on({
method: 'GET',
path: '/testok',
reply: {
status: 200,
headers: { 'content-type': 'text/html' },
body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
}
});
var url = TARGET_MOCKED_SERVER_BASEURL + '/testok';
request(BASE_IFRAMELY_SERVER_URL)
.get('/iframely?url=' + url)
.end(function(err, res) {
chai.expect(res.body.meta.description).to.equal('custom description for test.com domain');
done(err);
});
});
it('should use a core plugin if no custom plugin exists', function(done) {
targetMockedServer.on({
method: 'GET',
path: '/test-another',
reply: {
status: 200,
headers: { 'content-type': 'text/html' },
body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
}
});
var url = TARGET_MOCKED_SERVER_BASEURL + '/test-another';
request(BASE_IFRAMELY_SERVER_URL)
.get('/iframely?url=' + url)
.end(function(err, res) {
chai.expect(res.body.meta.description).to.equal('my description');
done(err);
});
});
it('should use a custom plugin overriding a core plugin ', function(done) {
targetMockedServer.on({
method: 'GET',
path: '/testok',
reply: {
status: 200,
headers: { 'content-type': 'text/html' },
body: "<html><title>my title</title><meta name='description' content='my description'><body>Hi there!</body></html>"
}
});
var url = TARGET_MOCKED_SERVER_BASEURL + '/testok';
request(BASE_IFRAMELY_SERVER_URL)
.get('/iframely?url=' + url)
.end(function(err, res) {
chai.expect(res.body.meta.title).to.equal('TITLE FROM CUSTOM-PLUGIN');
done(err);
});
});
});