Files
technical-services-exchange/tools/google-sheets-wo-parser/tests/run-tests.cjs
T
Codex 62220186af Add external import sources, work history, screening fields and Phase 1 docs
- New ExternalImportSource and ExternalWorkHistoryEntry models, controller and migrations
- Screening fields on external profile imports
- Admin and provider profile views, routes and workflow tests updated
- Phase 1 validation, route inventory, gap report template and roadmap docs
- Add the Google Sheets work-order parser tool (tools/google-sheets-wo-parser)
2026-10-02 15:50:18 -05:00

44 lines
2.0 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const vm = require('vm');
const assert = require('assert/strict');
const fixtures = require('./fixtures.cjs');
const context = { console, Date, Math, Number, String, Object, RegExp };
vm.createContext(context);
for (const file of ['Config.gs', 'Parsers.gs', 'Code.gs']) {
const source = fs.readFileSync(path.join(__dirname, '..', 'src', file), 'utf8')
.replace(/^const /gm, 'var ');
vm.runInContext(source, context, { filename: file });
}
const fieldNation = context.parseWorkOrderMessage_(fixtures.fieldNationNew);
assert.equal(fieldNation.ok, true);
assert.equal(fieldNation.record.platform, 'Field Nation');
assert.equal(fieldNation.record.workOrderId, '19660234');
assert.equal(fieldNation.record.payTotal, 225);
assert.equal(fieldNation.record.effectiveRate, 75);
assert.equal(fieldNation.record.city, 'Raleigh');
const workMarket = context.parseWorkOrderMessage_(fixtures.workMarketRouted);
assert.equal(workMarket.ok, true);
assert.equal(workMarket.record.platform, 'WorkMarket');
assert.equal(workMarket.record.notificationType, 'Routed');
assert.equal(workMarket.record.workOrderId, 'WM-884221');
assert.equal(workMarket.record.payType, 'Fixed Rate');
const unknown = context.parseWorkOrderMessage_(fixtures.unknown);
assert.equal(unknown.ok, false);
assert.equal(context.isSupportedPlatformSender_('Field Nation <alerts@fieldnation.com>'), true);
assert.equal(context.isSupportedPlatformSender_('WorkMarket <no-reply@workmarket.com>'), true);
assert.equal(context.isSupportedPlatformSender_('Unrelated sender <alerts@example.com>'), false);
assert.equal(
context.buildPlatformInboxQuery_({ lookbackDays: 7 }, { getName: () => 'WO Parser/Processed' }),
'in:inbox {from:fieldnation from:workmarket} -label:"WO Parser/Processed" newer_than:7d'
);
assert.equal(context.isPublicTemplate_({ getId: () => context.WO_PARSER.TEMPLATE_SPREADSHEET_ID }), true);
assert.equal(context.isPublicTemplate_({ getId: () => 'recipient-copy-id' }), false);
console.log('Parser fixtures passed.');