PageSourceSearch

https://www.comirnaty.com/lib/blocks/find-a-doctor/find-doctor-search.test.js

js comirnaty.com collected 2026-09-25 20:50:24 UTC 4,784 bytes, 131 lines download raw bytes

1/* global describe, beforeEach, it */
2import { expect } from '@esm-bundle/chai';
3// eslint-disable-next-line import/extensions
4import DoctorSearch from './find-doctor-search-example.mjs';
5// eslint-disable-next-line import/extensions
6import mockDoctorData from './find-doctor-search.mock.mjs';
7// eslint-disable-next-line import/extensions
8const schemaExample = await fetch(new URL('./find-doctor-search-schema.json', import.meta.url)).then((res) => res.json());
9
10describe('DoctorSearch', async () => {
11  let doctorSearch;
12
13  beforeEach(async () => {
14    doctorSearch = new DoctorSearch(mockDoctorData);
15  });
16
17  it('should initialize with data', async () => {
18    expect(doctorSearch.data).to.equal(mockDoctorData);
19  });
20
21  describe('Search by name', async () => {
22    it('should search by first name', async () => {
23      const results = doctorSearch.searchByName('Dennis');
24      expect(results).to.have.lengthOf(1);
25      expect(results[0].name.firstName).to.equal('Dennis');
26    });
27
28    it('should search by last name', async () => {
29      const results = doctorSearch.searchByName('Alvarez');
30      expect(results).to.have.lengthOf(1);
31      expect(results[0].name.lastName).to.equal('Alvarez Cardona');
32    });
33
34    it('should search case-insensitively', async () => {
35      const results = doctorSearch.searchByName('dennis');
36      expect(results).to.have.lengthOf(1);
37      expect(results[0].name.firstName).to.equal('Dennis');
38    });
39  });
40
41  describe('Search by specialty', async () => {
42    it('should search by specialty name', async () => {
43      const results = doctorSearch.searchBySpecialty('Internal Medicine');
44      expect(results).to.have.lengthOf(2);
45    });
46
47    it('should search by sub-specialty', async () => {
48      const results = doctorSearch.searchBySpecialty('Cardiovascular Disease');
49      expect(results).to.have.lengthOf(2);
50    });
51
52    it('should return empty array for non-existent specialty', async () => {
53      const results = doctorSearch.searchBySpecialty('XoXoXOoxo');
54      expect(results).to.have.lengthOf(0);
55    });
56  });
57
58  describe('Search by location', async () => {
59    it('should search by zipcode', async () => {
60      const results = doctorSearch.searchByLocation('10011');
61      expect(results).to.have.lengthOf(1);
62      expect(results[0].name.firstName).to.equal('Dennis');
63    });
64
65    it('should return empty array for non-existent zipcode', async () => {
66      const results = doctorSearch.searchByLocation('99999');
67      expect(results).to.have.lengthOf(0);
68    });
69  });
70
71  describe('Combined search', async () => {
72    it('should handle empty criteria and return all doctors', async () => {
73      const results = doctorSearch.search({});
74      expect(results).to.have.lengthOf(2);
75    });
76
77    it('should verify doctor details', async () => {
78      const results = doctorSearch.search({ name: 'Finkielstein' });
79      expect(results).to.have.lengthOf(1);
80      const doctor = results[0];
81
82      expect(doctor.name.prefix).to.equal('Dr');
83      expect(doctor.name.suffix).to.equal('MD');
84      expect(doctor.name.title).to.equal('Internal Medicine Physician- Cardiovascular Disease');
85      expect(doctor.practices[0].name).to.include('Northwell');
86      expect(doctor.practices[0].address).to.equal('7 7th Avenue Floor 3');
87      expect(doctor.specialties[0].name).to.equal('Internal Medicine Physician');
88      expect(doctor.specialties[0].subSpecialty).to.equal('Cardiovascular Disease');
89      expect(doctor.education[0].institution).to.include('Stony Brook');
90    });
91
92    it('should validate mock data against the schema', async () => {
93      const validSchema = schemaExample;
94      // eslint-disable-next-line no-underscore-dangle
95      const mockExample = mockDoctorData.hits.hits[0]._source;
96
97      const keyArray = [
98        'provider_id',
99        'first_name',
100        'last_name',
101        'prefix',
102        'credential_name',
103        'specialty_name',
104        'specialty',
105        'practice',
106        'language',
107        'insurance',
108        'education',
109        'residency',
110      ];
111
112      // Confirm schema has required keys
113      keyArray.forEach((key) => {
114        expect(validSchema).to.have.property(key);
115      });
116
117      // Confirm mock data has required keys
118      Object.keys(mockExample).forEach((key) => {
119        expect(validSchema).to.have.property(key);
120      });
121
122      // Validate nested object schemas
123      expect(validSchema.specialty.type).to.equal('nested');
124      expect(validSchema.practice.type).to.equal('nested');
125      expect(validSchema.language.type).to.equal('nested');
126      expect(validSchema.insurance.type).to.equal('nested');
127      expect(validSchema.education.type).to.equal('nested');
128      expect(validSchema.residency.type).to.equal('nested');
129    });
130  });
131});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.