-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbatch-get.test.js
82 lines (73 loc) · 2.26 KB
/
batch-get.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
'use strict';
const proxyquire = require('proxyquire');
const expect = require('chai').expect;
const redirectedFixture = require('./fixtures/redirected.json');
const justasFastFtFixture = require('./fixtures/justasfastft.json');
const metricsMock = require('./utils/metrics-mock');
const mockInstance = {
batchGetItem: (opts, cb) => {
cb(null, {
Responses: {
urlmgmtapi_primary: [
redirectedFixture.Item,
justasFastFtFixture.Item
]
}
});
}
};
const main = proxyquire('..', {
'./lib/dynamos': {
init: () => null,
get: function (name) {
return this[name];
},
primary: { table: 'urlmgmtapi_primary', instance: mockInstance },
replica: { table: 'urlmgmtapi_replica', instance: mockInstance }
}
});
describe('#batchGet', () => {
before(() => main.init({ metrics: metricsMock, timeout: 500 }));
it('should #get /redirected and /justasfastft', () => {
return main.batchGet(['https://www.ft.com/redirected', 'https://www.ft.com/justasfastft'])
.then(data => {
expect(data).to.eql([
{
code: 100,
fromURL: 'https://www.ft.com/redirected',
toURL: 'https://www.ft.com/stream/brandId/NTlhNzEyMzMtZjBjZi00Y2U1LTg0ODUtZWVjNmEyYmU1NzQ2-QnJhbmRz'
},
{
code: 100,
fromURL: 'https://www.ft.com/justasfastft',
toURL: 'https://www.ft.com/stream/brandId/NTlhNzEyMzMtZjBjZi00Y2U1LTg0ODUtZWVjNmEyYmU1NzQ2-QnJhbmRz'
}
]);
});
});
it('should return a vanity-like response if the database doesn\'t contain a url', () => {
return main.batchGet(['https://www.ft.com/redirected', 'https://www.ft.com/unknown'])
.then(data => {
expect(data).to.eql([
{
code: 100,
fromURL: 'https://www.ft.com/redirected',
toURL: 'https://www.ft.com/stream/brandId/NTlhNzEyMzMtZjBjZi00Y2U1LTg0ODUtZWVjNmEyYmU1NzQ2-QnJhbmRz'
},
{
code: 100,
fromURL: 'https://www.ft.com/unknown',
toURL: 'https://www.ft.com/unknown'
}
]);
});
});
it('should reject urls with trailing slashes to the slash-less url', () => {
return main.batchGet(['https://www.ft.com/redirected/'])
.then(() => {
throw new Error('should have thrown');
}, err => {
expect(err.toString()).to.contain('Trailing slash redirection to trimmed URLs not supported');
});
});
});