-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed broken tests, added test for validateAddressesWithGoogleMaps
- Loading branch information
Showing
8 changed files
with
142 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...addresses/validate-addresses-with-google-maps/validate-addresses-with-google-maps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { validateAddressesWithGoogleMaps } from '@/services/server/validate-addresses/validate-addresses-with-google-maps'; | ||
import { Builder } from 'builder-pattern'; | ||
import type { ProcessableResponse } from '@/services/server/validate-addresses/validate-addresses-with-google-maps/types/processable-response'; | ||
import type { Address } from '@/model/types/addresses/address'; | ||
|
||
describe('validateAddressesWithGoogleMaps', () => { | ||
it('Returns an empty array if all addresses it receives are valid.', async () => { | ||
const address: Address = { | ||
streetLine1: '1600 Amphitheatre Pkwy', | ||
city: 'Mountain View', | ||
state: 'CA', | ||
zip: '94043', | ||
}; | ||
|
||
jest.spyOn(globalThis, 'fetch').mockImplementation(() => { | ||
console.log('spy called'); | ||
|
||
const response = Builder<Response>() | ||
.ok(true) | ||
.json(() => { | ||
const processableResponseBody: ProcessableResponse = { | ||
result: { | ||
verdict: { | ||
hasUnconfirmedComponents: false, | ||
}, | ||
address: { | ||
postalAddress: { | ||
postalCode: address.zip, | ||
administrativeArea: address.state, | ||
locality: address.city, | ||
addressLines: [address.streetLine1], | ||
}, | ||
addressComponents: [ | ||
{ | ||
componentName: { | ||
text: address.streetLine1.slice(0, 4), | ||
}, | ||
componentType: 'street_number', | ||
confirmationLevel: 'CONFIRMED', | ||
}, | ||
{ | ||
componentName: { | ||
text: address.streetLine1.slice(5), | ||
}, | ||
componentType: 'route', | ||
confirmationLevel: 'CONFIRMED', | ||
}, | ||
{ | ||
componentName: { | ||
text: address.city, | ||
}, | ||
componentType: 'locality', | ||
confirmationLevel: 'CONFIRMED', | ||
}, | ||
{ | ||
componentName: { | ||
text: address.state, | ||
}, | ||
componentType: 'administrative_area_level_1', | ||
confirmationLevel: 'CONFIRMED', | ||
}, | ||
{ | ||
componentName: { | ||
text: address.zip, | ||
}, | ||
componentType: 'postal_code', | ||
confirmationLevel: 'CONFIRMED', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
return Promise.resolve(processableResponseBody); | ||
}) | ||
.build(); | ||
|
||
return Promise.resolve(response); | ||
}); | ||
|
||
const result = await validateAddressesWithGoogleMaps({ | ||
homeAddress: address, | ||
mailingAddress: address, | ||
previousAddress: address, | ||
}); | ||
|
||
expect(result).toStrictEqual([]); | ||
}); | ||
|
||
// it(`throws a ServerError if the response received from the Google maps API is | ||
// not ok.`, () => {}); | ||
|
||
// it(`throws a ServerError if the response received from the Google maps API | ||
// cannot be processed due to missing or invalid properties.`, () => {}); | ||
|
||
// it(`returns an array containing an UnconfirmedComponentsError if the address | ||
// has components that could not be confirmed.`, () => {}); | ||
|
||
// it(`returns an array containing a ReviewRecommendedAddressError if the | ||
// address did not contain unconfirmed components but a more accurate address | ||
// was found.`, () => {}); | ||
|
||
// it(`returns an array containing a MissingSubpremiseError if a missing | ||
// subpremise was detected.`, () => {}); | ||
|
||
// it(`returns an array containing multiple error types when multiple problems | ||
// are detected.`, () => {}); | ||
|
||
/* | ||
The following tests can be uncommented to test against the actual | ||
Google Maps API. | ||
*/ | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/__tests__/unit/utils/shared/collapse-whitespace.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { collapseWhitespace } from '@/utils/shared/collapse-whitespace'; | ||
|
||
describe('collapseWhitespace', () => { | ||
const whitespace = ' \t\n\r '; | ||
const collapsed = 'The quick brown fox jumps over the lazy dog'; | ||
|
||
test(`It collapses groups of whitespace characters within a string into | ||
single space characters.`, () => { | ||
const expanded = collapsed.split(' ').join(whitespace); | ||
expect(collapseWhitespace(expanded)).toBe(collapsed); | ||
}); | ||
|
||
test('It removes whitespace at the start and end of a string.', () => { | ||
const testString = whitespace + collapsed + whitespace; | ||
expect(collapseWhitespace(testString)).toBe(collapsed); | ||
}); | ||
}); |