test-numbers-generator
Version:
Generate and validate European test phone numbers (mobile and landline) in safe, non-existent ranges.
61 lines (55 loc) • 1.93 kB
text/typescript
import { getRandomPlaatsnaam } from '../postcodeService';
// Mock fetch globally
(global as any).fetch = jest.fn(async (url: string) => {
// 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 as any).fetch = jest.fn(async (url: string) => {
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 as any).fetch = originalFetch;
});
it('should return a string (plaatsnaam)', async () => {
const plaatsnaam = await getRandomPlaatsnaam();
// Controleer of het resultaat een string is (en niet een object)
expect(typeof plaatsnaam).toBe('string');
expect(plaatsnaam).toBeTruthy();
});
});