Skip to content

Commit 5df35b3

Browse files
committed
Fix check_key when sublicensee preset, add regression test
1 parent ced7662 commit 5df35b3

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

libs/fake/webservices.fake.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,11 @@ fake.registerWebservice('https://api.ideal-postcodes.co.uk/v1/keys/idklicensees'
15621562
return (data.licensee === "testlicensee") ? keyCheckPass : uncataloguedError;
15631563
});
15641564

1565+
// Mocked Licensees Requests
1566+
fake.registerWebservice('https://api.ideal-postcodes.co.uk/v1/keys/iddlicensees', function(data) {
1567+
return (data.licensee === "testlicensee") ? keyCheckPass : keyCheckFail;
1568+
});
1569+
15651570
fake.registerWebservice('https://api.ideal-postcodes.co.uk/v1/postcodes/id11li', function(data) {
15661571
return (data.licensee === "testlicensee") ? testPostcodeResult : uncataloguedError;
15671572
});

src/jquery.postcodes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,11 @@
824824

825825
// Check if key is usable if necessary
826826
if (options.check_key) {
827-
$.idealPostcodes.checkKey({
828-
api_key: options.api_key
829-
}, initPlugin, failedKeyCheck);
827+
var keyOptions = { api_key: options.api_key };
828+
if (options.licensee) {
829+
keyOptions.licensee = options.licensee;
830+
}
831+
$.idealPostcodes.checkKey(keyOptions, initPlugin, failedKeyCheck);
830832
} else {
831833
initPlugin();
832834
}

test/test/plugin_basic.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,29 @@
185185
equal($lookup_button.length, 0, "there is no button");
186186
});
187187

188+
module("Sublicensee: Pre-initialisation check", {
189+
setup: function () {
190+
stop();
191+
var startTests = function () {
192+
$input_field = $("#"+defaults.input_id);
193+
$lookup_button = $("#"+defaults.button_id);
194+
start();
195+
};
196+
$("#postcode_lookup_field").setupPostcodeLookup({
197+
// Test key which will return false
198+
api_key: "iddlicensees",
199+
licensee: "testlicensee",
200+
check_key: true,
201+
disable_interval: 0,
202+
onFailedCheck: startTests,
203+
onLoaded: startTests
204+
});
205+
}
206+
});
207+
208+
test("has postcode lookup tools setup", 2, function () {
209+
equal($input_field.length, 1, "there is postcode input");
210+
equal($lookup_button.length, 1, "there is button");
211+
});
212+
188213
}(jQuery));

0 commit comments

Comments
 (0)