wbxcallprov/test/google.test.js
jmcqueen 6de5392e90
Some checks are pending
CI / verify (push) Waiting to run
Add node:test suite and Gitea Actions CI
- 30-test suite (node --test, no framework) covering the exact functions
  that have regressed in previous rounds:
    * parseStoreArg / parseStoreNumber / storeEmail (helpers)
    * greetingForBrand (brand fallback)
    * formatE911Address / formatSuite (google response reducer)
    * parseNextLink (RFC-5988 pagination — now exported)
    * runStep success / non-critical / critical / no-bot paths
- test/setup.js stubs required env vars so any src/ module can be
  imported cleanly; loaded via --import once per test process
- npm run test wired up; directory form works on Node 20 + 22
- .gitea/workflows/ci.yml runs lint + format:check + test on push/PR
  to main, on Node 22 to match the runtime image
- Exclude test/ and .gitea/ from the Docker build context
- Exclude docker/ from bot Prettier scope (remote-agent is its own
  sub-project with its own tooling)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 16:07:02 -04:00

55 lines
2.4 KiB
JavaScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { formatE911Address, formatSuite } from '../src/integrations/google.js';
// Minimal shape of the Google Address Validation response we care about.
function makeResponse(components) {
return { result: { address: { addressComponents: components } } };
}
const fullAddress = makeResponse([
{ componentType: 'street_number', componentName: { text: '77' } },
{ componentType: 'route', componentName: { text: 'Willowbrook Rd' } },
{ componentType: 'subpremise', componentName: { text: 'Ste 2091' } },
{ componentType: 'locality', componentName: { text: 'Wayne' } },
{ componentType: 'administrative_area_level_1', componentName: { text: 'NJ' } },
{ componentType: 'postal_code', componentName: { text: '07470' } },
{ componentType: 'country', componentName: { text: 'United States' } },
]);
describe('formatE911Address', () => {
it('flattens the address components into an E911-shaped string', () => {
assert.equal(formatE911Address(fullAddress), '77 Willowbrook Rd, Wayne, NJ 07470');
});
it('tolerates missing components without crashing', () => {
const partial = makeResponse([
{ componentType: 'street_number', componentName: { text: '10' } },
{ componentType: 'route', componentName: { text: 'Main St' } },
{ componentType: 'locality', componentName: { text: 'Anywhere' } },
]);
// Missing state/zip render as empty slots; the join stays intact.
assert.equal(formatE911Address(partial), '10 Main St, Anywhere,');
});
it('handles an empty component list', () => {
// The template renders three comma-separated sections; with every
// field empty they collapse to just the separators after trim.
assert.equal(formatE911Address(makeResponse([])), ', ,');
});
});
describe('formatSuite', () => {
it('returns the subpremise text when present', () => {
assert.equal(formatSuite(fullAddress), 'Ste 2091');
});
it('returns empty string when there is no subpremise', () => {
const noSuite = makeResponse([
{ componentType: 'street_number', componentName: { text: '77' } },
{ componentType: 'route', componentName: { text: 'Willowbrook Rd' } },
]);
assert.equal(formatSuite(noSuite), '');
});
});