mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
Keep the place suggester's fair-use and privacy promises
- One spacing, pause and cache for the whole tab, so a search box put up again does not start afresh. - A failed request or a timeout pauses suggestions for a minute, as a refusal does. - A number named as a card, a phone or an account keeps its digits together, so no address is read out of them; a UK postcode written without its space is a place, not a password. - The docs say exactly what is sent. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
9ec95102ca
commit
c06aa37ce2
5 files changed
+126
-47
No files matched your search
@@ -5,8 +5,12 @@ import {
|
||||
createPlaceSuggester,
|
||||
inExtent,
|
||||
mayBePrivate,
|
||||
resetPlaceSuggestions,
|
||||
} from './placeSuggestions.js';
|
||||
|
||||
// The spacing, pause and cache are the tab's: each test starts clean.
|
||||
test.beforeEach(() => resetPlaceSuggestions());
|
||||
|
||||
test('Photon suggestions keep distinct valid candidates and their region bounds', async () => {
|
||||
const texas = {
|
||||
geometry: { type: 'Point', coordinates: [-99, 31] },
|
||||
@@ -278,3 +282,48 @@ test('cards, phones, IBANs, keys and passwords are private', () => {
|
||||
])
|
||||
assert.equal(mayBePrivate(text), false, text);
|
||||
});
|
||||
|
||||
const answering = (calls, answer) => async (url) => {
|
||||
calls.push(String(url));
|
||||
if (answer instanceof Error) throw answer;
|
||||
return { ok: true, json: async () => ({ features: [] }) };
|
||||
};
|
||||
|
||||
test('a failed or timed-out request pauses suggestions as a refusal does', async () => {
|
||||
const calls = [];
|
||||
const suggester = createPlaceSuggester({
|
||||
endpoint: 'https://photon.test/api/',
|
||||
fetchImpl: answering(calls, new TypeError('Failed to fetch')),
|
||||
});
|
||||
assert.deepEqual(await suggester.suggest('Paris'), []);
|
||||
assert.deepEqual(await suggester.suggest('Berlin'), []);
|
||||
assert.equal(calls.length, 1);
|
||||
});
|
||||
|
||||
test('every suggester in the tab keeps one spacing and one pause', async () => {
|
||||
const calls = [];
|
||||
const options = {
|
||||
endpoint: 'https://photon.test/api/',
|
||||
fetchImpl: answering(calls),
|
||||
};
|
||||
const first = createPlaceSuggester(options);
|
||||
const second = createPlaceSuggester(options);
|
||||
const started = Date.now();
|
||||
await Promise.all([first.suggest('Paris'), second.suggest('Berlin')]);
|
||||
assert.equal(calls.length, 2);
|
||||
assert.ok(Date.now() - started >= 490);
|
||||
});
|
||||
|
||||
test('a number named as a card or a phone stays private', () => {
|
||||
for (const line of [
|
||||
'card 4111 111111 thanks',
|
||||
'call 0207 946095 now',
|
||||
'phone 12 345678 home',
|
||||
])
|
||||
assert.equal(mayBePrivate(line), true, line);
|
||||
});
|
||||
|
||||
test('a UK postcode without its space is a place', () => {
|
||||
for (const line of ['EC1A1BB', 'W1A0AX', 'BT487NN'])
|
||||
assert.equal(mayBePrivate(line), false, line);
|
||||
});
|
||||
Reference in new issue
Block a user