test-numbers-generator
Version:
Generate and validate European test phone numbers (mobile and landline) in safe, non-existent ranges.
58 lines (57 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const postcodeService_1 = require("../postcodeService");
// Mock fetch globally
global.fetch = jest.fn(async (url) => {
// Simuleer verschillende resultaten afhankelijk van de query
if (url.includes('woonplaatsnaam:A*')) {
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: 'Almere' }, { woonplaatsnaam: 'Aalten' }] } })
};
}
if (url.includes('woonplaatsnaam:Z*')) {
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: 'Zwolle' }, { woonplaatsnaam: 'Zutphen' }] } })
};
}
// Default: return een random plaatsnaam
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: 'Breda' }] } })
};
});
describe('getRandomPlaatsnaam', () => {
const originalFetch = global.fetch;
beforeEach(() => {
global.fetch = jest.fn(async (url) => {
if (url.includes('woonplaatsnaam:A*')) {
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: "Almere" }, { woonplaatsnaam: "Aalten" }, { woonplaatsnaam: "'s-Heer Abtskerke" }] } })
};
}
if (url.includes('woonplaatsnaam:Z*')) {
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: 'Zwolle' }, { woonplaatsnaam: 'Zutphen' }] } })
};
}
// Default: return een random plaatsnaam
return {
ok: true,
json: async () => ({ response: { docs: [{ woonplaatsnaam: 'Breda' }] } })
};
});
});
afterEach(() => {
global.fetch = originalFetch;
});
it('should return a string (plaatsnaam)', async () => {
const plaatsnaam = await (0, postcodeService_1.getRandomPlaatsnaam)();
// Controleer of het resultaat een string is (en niet een object)
expect(typeof plaatsnaam).toBe('string');
expect(plaatsnaam).toBeTruthy();
});
});