Nativefier/test/module/inferUserAgentSpec.js

48 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-03-25 12:29:33 +01:00
import chai from 'chai';
import _ from 'lodash';
import inferUserAgent from './../../lib/infer/inferUserAgent';
2016-03-25 12:29:33 +01:00
const assert = chai.assert;
const TEST_RESULT = {
darwin: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
win32: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
linux: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
2016-03-25 12:29:33 +01:00
};
function testPlatform(platform) {
return inferUserAgent('0.37.1', platform)
.then((userAgent) => {
assert.equal(userAgent, TEST_RESULT[platform], 'Correct user agent should be inferred');
2016-03-25 12:29:33 +01:00
});
}
describe('Infer User Agent', function () {
this.timeout(15000);
it('Can infer userAgent for all platforms', (done) => {
const testPromises = _.keys(TEST_RESULT).map(platform => testPlatform(platform));
Promise
2016-03-25 12:29:33 +01:00
.all(testPromises)
.then(() => {
done();
2016-03-25 12:29:33 +01:00
})
.catch((error) => {
done(error);
2016-03-25 12:29:33 +01:00
});
});
2016-03-25 13:10:56 +01:00
it('Connection error will still get a user agent', (done) => {
const TIMEOUT_URL = 'http://www.google.com:81/';
inferUserAgent('1.6.7', 'darwin', TIMEOUT_URL)
.then((userAgent) => {
assert.equal(
2016-03-25 13:10:56 +01:00
userAgent,
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Expect default user agent on connection error',
2016-03-25 13:10:56 +01:00
);
done();
2016-03-25 13:10:56 +01:00
})
.catch(done);
});
2016-03-25 12:29:33 +01:00
});