Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/src/adapters/HouseholdAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ export class HouseholdAdapter {
// Convert snake_case to camelCase for internal representation
const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
householdData[camelKey] = value as any;
} catch (error) {
// If entity not found in metadata, still include it but log warning
console.warn(`Entity "${key}" not found in metadata, including anyway`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: We do want console.warn statements. We'll use these with RUM monitoring down the road to diagnose bugs.

} catch {
// If entity not found in metadata, still include it
const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
householdData[camelKey] = value as any;
}
Expand Down Expand Up @@ -125,7 +124,6 @@ export class HouseholdAdapter {
} else {
// If not found in metadata, try snake_case conversion
const snakeKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
console.warn(`Entity "${key}" not found in metadata, using snake_case "${snakeKey}"`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: Here, too, let's keep the console.warn()

household_json[snakeKey] = value as any;
}
}
Expand Down
24 changes: 1 addition & 23 deletions app/src/adapters/SimulationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ export class SimulationAdapter {
* Converts SimulationMetadata from API GET response to Simulation type
*/
static fromMetadata(metadata: SimulationMetadata): Simulation {
console.log('[SimulationAdapter.fromMetadata] RAW API METADATA:', {
id: metadata.id,
status: metadata.status,
hasOutput: !!metadata.output,
outputType: typeof metadata.output,
metadataKeys: Object.keys(metadata),
});

if (!metadata.population_id) {
throw new Error('Simulation metadata missing population_id');
}
Expand All @@ -45,13 +37,7 @@ export class SimulationAdapter {
if (metadata.output && typeof metadata.output === 'string') {
try {
parsedOutput = JSON.parse(metadata.output);
console.log('[SimulationAdapter.fromMetadata] Parsed stringified output:', {
originalType: 'string',
parsedType: typeof parsedOutput,
parsedKeys: parsedOutput ? Object.keys(parsedOutput) : [],
});
} catch (error) {
console.error('[SimulationAdapter.fromMetadata] Failed to parse output:', error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: Let's keep this console.error()

} catch {
// Keep original value if parsing fails
parsedOutput = metadata.output;
}
Expand All @@ -70,14 +56,6 @@ export class SimulationAdapter {
status: metadata.status,
};

console.log('[SimulationAdapter.fromMetadata] TRANSFORMED SIMULATION:', {
id: simulation.id,
status: simulation.status,
hasOutput: !!simulation.output,
outputType: typeof simulation.output,
simulationKeys: Object.keys(simulation),
});

return simulation;
}

Expand Down
32 changes: 5 additions & 27 deletions app/src/adapters/conversionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { PolicyMetadataParams, PolicyMetadataParamValues } from '@/types/metadat
import { Parameter } from '@/types/subIngredients/parameter';
import { ValueInterval } from '@/types/subIngredients/valueInterval';

// Helper to detect Immer Proxy objects
function isProxy(obj: any): boolean {
return obj != null && typeof obj === 'object' && obj.constructor?.name === 'DraftObject';
}

/**
* Converts PolicyMetadataParamValues (with "startDate.endDate" keys) into ValueInterval array
* Copied from src/libs/policyParameterTransform.ts
Expand Down Expand Up @@ -51,32 +46,15 @@ export function convertPolicyJsonToParameters(policyJson: PolicyMetadataParams):
* Converts Parameter[] to PolicyMetadataParams format for API payloads
*/
export function convertParametersToPolicyJson(parameters: Parameter[]): PolicyMetadataParams {
console.log('[ADAPTER] convertParametersToPolicyJson - START');
console.log('[ADAPTER] parameters:', parameters);

const data: PolicyMetadataParams = {};

parameters.forEach((param, paramIndex) => {
console.log(`[ADAPTER] Processing parameter ${paramIndex}:`, param);
console.log(`[ADAPTER] param is Proxy?`, isProxy(param));
console.log(`[ADAPTER] param.values:`, param.values);
console.log(`[ADAPTER] param.values is Array?`, Array.isArray(param.values));

if (param.values && param.values.length > 0) {
console.log(`[ADAPTER] First value:`, param.values[0]);
console.log(`[ADAPTER] First value is Proxy?`, isProxy(param.values[0]));
}

data[param.name] = param.values.reduce((acc, cur, valueIndex) => {
console.log(`[ADAPTER] Processing value ${valueIndex}:`, cur);
console.log(`[ADAPTER] cur is Proxy?`, isProxy(cur));
return { ...acc, [`${cur.startDate}.${cur.endDate}`]: cur.value };
}, {});
parameters.forEach((param) => {
data[param.name] = param.values.reduce(
(acc, cur) => ({ ...acc, [`${cur.startDate}.${cur.endDate}`]: cur.value }),
{}
);
});

console.log('[ADAPTER] convertParametersToPolicyJson - END');
console.log('[ADAPTER] Final data:', data);

return data;
}

Expand Down
12 changes: 3 additions & 9 deletions app/src/tests/unit/adapters/HouseholdAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ describe('HouseholdAdapter', () => {
expect(result.householdData.maritalUnits).toEqual(metadata.household_json.marital_units);
});

test('given entity not in metadata then logs warning but includes it anyway', () => {
test('given entity not in metadata then includes it anyway', () => {
const result = HouseholdAdapter.fromMetadata(mockHouseholdMetadataWithUnknownEntity);

expect(console.warn).toHaveBeenCalledWith(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, non-blocking: Perhaps better to keep this, since we'd be looking to keep the console.warn(), as well

'Entity "unknown_entity" not found in metadata, including anyway'
);
expect(result.householdData).toHaveProperty('unknownEntity');
expect(result.householdData.unknownEntity).toEqual(
// @ts-expect-error
Expand Down Expand Up @@ -179,12 +176,9 @@ describe('HouseholdAdapter', () => {
});
});

test('given entity not in metadata then toCreationPayload logs warning and uses snake_case', () => {
test('given entity not in metadata then toCreationPayload uses snake_case', () => {
const result = HouseholdAdapter.toCreationPayload(mockHouseholdDataWithUnknownEntity, 'uk');

expect(console.warn).toHaveBeenCalledWith(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, non-blocking: Better to keep

'Entity "customEntity" not found in metadata, using snake_case "custom_entity"'
);
expect(result.data).toHaveProperty('custom_entity');
// @ts-expect-error
expect(result.data.custom_entity).toEqual(mockHouseholdDataWithUnknownEntity.customEntity);
Expand Down Expand Up @@ -253,7 +247,7 @@ describe('HouseholdAdapter', () => {
const result = HouseholdAdapter.fromMetadata(metadata as any);

expect(result.householdData.people).toBeDefined();
expect(console.warn).toHaveBeenCalled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, non-blocking: Here, too

expect(result.householdData.taxUnits).toBeDefined();
});

test('given complex nested snake_case then converts correctly to camelCase', () => {
Expand Down
Loading