|
/*global describe, it, expect, IG */ |
|
/*jshint es5:true*/ |
|
(function () { |
|
'use strict'; |
|
|
|
describe('parseSpreadsheetKey', function () { |
|
// Prepare some values for testing |
|
var key = '0Ajt08GcPGJRbdFJUZWZfZ3M1V0xDaTFBckJnNENCSGc'; |
|
var gsURLs = [ |
|
'https://docs.google.com/a/ft.com/spreadsheet/ccc?key=' + key, |
|
'https://docs.google.com/a/ft.com/spreadsheet/ccc?key=' + key + '#hash', |
|
'https://docs.google.com/a/ft.com/spreadsheet/ccc?key=' + key + '&foo=bar', |
|
'https://docs.google.com/a/ft.com/spreadsheet/ccc?key=' + key + '&foo=bar#hash', |
|
]; |
|
var berthaURLs = []; |
|
([ |
|
'bertha.ig.ft.com', |
|
'spottiswood.herokuapp.com', |
|
'staging.bertha.ig.ft.com', |
|
'spottiswood-tupp.herokuapp.com' |
|
]).forEach(function (host) { |
|
berthaURLs = berthaURLs.concat([ |
|
'http://' + host + '/view/publish/ig/' + key, |
|
'http://' + host + '/republish/publish/ig/' + key + '/basic,foo', |
|
'http://' + host + '/view/publish/ig/' + key + '?callback=hi' |
|
]); |
|
}); |
|
var invalidStrings = [ |
|
'ab==gsgsc....asdfasdf 891 sd', // invalid chars |
|
'https://mops.google.com/a/ft.com/spreadsheet/ccc?key=' + key, // wrong hostname |
|
'0Ajt08GcPGJRbdFJUZWZfZ3M1V0xDaTFBckJnNENCSGc/', // slash at end |
|
'0Ajt08GcPGJRbdFJUZWZfZ', // too short |
|
'0Ajt08GcPGJRbdFJUZWZfZ3M1V0xDaTFBckJnNENCSGc0Ajt08GcPGJRbdFJUZWZfZ3M1V0xDaTFBckJnNENCSGc' // too long |
|
]; |
|
|
|
// Do tests |
|
it('handles a plain key', function () { |
|
expect(IG.parseSpreadsheetKey(key)).to.equal(key); |
|
}); |
|
|
|
it('handles a Google Spreadsheets URL', function () { |
|
gsURLs.forEach(function (url) { |
|
expect(IG.parseSpreadsheetKey(url)).to.equal(key); |
|
}); |
|
}); |
|
|
|
it('handles a Bertha URL at any of the known Bertha hosts', function () { |
|
berthaURLs.forEach(function (url) { |
|
expect(IG.parseSpreadsheetKey(url)).to.equal(key); |
|
}); |
|
}); |
|
|
|
it('throws on invalid strings', function () { |
|
invalidStrings.forEach(function (str) { |
|
expect(function () { |
|
IG.parseSpreadsheetKey(str); |
|
}).to.throw(/Cannot parse spreadsheet key from value/); |
|
}); |
|
}); |
|
|
|
it('returns null for invalid strings if "silent" flag is passed', function () { |
|
invalidStrings.forEach(function (str) { |
|
expect(function () { |
|
expect(IG.parseSpreadsheetKey(str, true)).to.equal(null); |
|
}).to.not.throw(Error); |
|
}); |
|
}); |
|
}); |
|
|
|
})(); |