Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3530,8 +3530,8 @@ const CONST = {

SAGE_INTACCT_EXPORT_DATE: {
LAST_EXPENSE: 'LAST_EXPENSE',
EXPORTED: 'EXPORTED',
SUBMITTED: 'SUBMITTED',
REPORT_EXPORTED: 'REPORT_EXPORTED',
REPORT_SUBMITTED: 'REPORT_SUBMITTED',
},

NETSUITE_CONFIG: {
Expand Down
4 changes: 2 additions & 2 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5390,11 +5390,11 @@ ${amount} für ${merchant} – ${date}`,
label: 'Datum der letzten Ausgabe',
description: 'Datum der letzten Ausgabe im Bericht.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Exportdatum',
description: 'Datum, an dem der Bericht nach Sage Intacct exportiert wurde.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Eingereichtes Datum',
description: 'Datum, an dem der Bericht zur Genehmigung eingereicht wurde.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5462,11 +5462,11 @@ ${amount} για ${merchant} - ${date}`,
label: 'Ημερομηνία τελευταίας δαπάνης',
description: 'Ημερομηνία της πιο πρόσφατης δαπάνης στην αναφορά.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Ημερομηνία εξαγωγής',
description: 'Ημερομηνία εξαγωγής της αναφοράς στο Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Ημερομηνία υποβολής',
description: 'Ημερομηνία υποβολής της αναφοράς για έγκριση.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5560,11 +5560,11 @@ const translations = {
label: 'Date of last expense',
description: 'Date of the most recent expense on the report.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Export date',
description: 'Date the report was exported to Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Submitted date',
description: 'Date the report was submitted for approval.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5316,11 +5316,11 @@ ${amount} para ${merchant} - ${date}`,
label: 'Fecha del último gasto',
description: 'Fecha del gasto más reciente del informe.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Fecha de exportación',
description: 'Fecha en la que se exportó el informe a Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Fecha de envío',
description: 'Fecha de presentación del informe para su aprobación.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5396,11 +5396,11 @@ ${amount} pour ${merchant} - ${date}`,
label: 'Date de la dernière dépense',
description: 'Date de la dépense la plus récente sur la note de frais.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Date d’exportation',
description: 'Date à laquelle la note de frais a été exportée vers Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Date de soumission',
description: 'Date à laquelle la note de frais a été soumise pour approbation.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5354,11 +5354,11 @@ ${amount} per ${merchant} - ${date}`,
label: "Data dell'ultima spesa",
description: 'Data della spesa più recente nel rendiconto.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Data di esportazione',
description: 'Data in cui il report è stato esportato in Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Data di invio',
description: "Data in cui il report è stato inviato per l'approvazione.",
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5308,11 +5308,11 @@ ${integrationName === CONST.ONBOARDING_ACCOUNTING_MAPPING.other ? 'あなたの'
label: '最終経費の日付',
description: 'レポート内で最新の経費の日付。',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'エクスポート日',
description: 'レポートが Sage Intacct にエクスポートされた日付。',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: '提出日',
description: 'レポートが承認申請として提出された日付。',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5353,11 +5353,11 @@ ${amount} voor ${merchant} - ${date}`,
label: 'Datum van laatste uitgave',
description: 'Datum van de meest recente uitgave in het rapport.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Exportdatum',
description: 'Datum waarop het rapport is geëxporteerd naar Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Ingediend op datum',
description: 'Datum waarop het rapport ter goedkeuring is ingediend.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5380,11 +5380,11 @@ ${amount} dla ${merchant} - ${date}`,
label: 'Data ostatniego wydatku',
description: 'Data najnowszego wydatku w raporcie.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Data eksportu',
description: 'Data wyeksportowania raportu do Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Data wysłania',
description: 'Data przesłania raportu do zatwierdzenia.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5347,11 +5347,11 @@ ${amount} para ${merchant} - ${date}`,
label: 'Data da última despesa',
description: 'Data da despesa mais recente no relatório.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: 'Data de exportação',
description: 'Data em que o relatório foi exportado para o Sage Intacct.',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: 'Data de envio',
description: 'Data em que o relatório foi enviado para aprovação.',
},
Expand Down
4 changes: 2 additions & 2 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5179,11 +5179,11 @@ ${amount},商户:${merchant} - 日期:${date}`,
label: '上次报销日期',
description: '报表中最近一笔报销的日期。',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.EXPORTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED]: {
label: '导出日期',
description: '报表导出到 Sage Intacct 的日期。',
},
[CONST.SAGE_INTACCT_EXPORT_DATE.SUBMITTED]: {
[CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED]: {
label: '提交日期',
description: '报表提交审批的日期。',
},
Expand Down
2 changes: 2 additions & 0 deletions src/libs/migrateOnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Log from './Log';
import ConvertGpsPointsTo2DArray from './migrations/ConvertGpsPointsTo2DArray';
import MoveFilesOutOfDocuments from './migrations/MoveFilesOutOfDocuments';
import MoveSearchQueryByHashToSnapshots from './migrations/MoveSearchQueryByHashToSnapshots';
import RenameLegacySageIntacctExportDate from './migrations/RenameLegacySageIntacctExportDate';
import ReplaceShouldUseStagingServerWithActiveServer from './migrations/ReplaceShouldUseStagingServerWithActiveServer';
import {endSpan, getSpan, startSpan} from './telemetry/activeSpans';

Expand All @@ -24,6 +25,7 @@ export default function () {
MoveFilesOutOfDocuments,
ReplaceShouldUseStagingServerWithActiveServer,
MoveSearchQueryByHashToSnapshots,
RenameLegacySageIntacctExportDate,
];

// Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the
Expand Down
56 changes: 56 additions & 0 deletions src/libs/migrations/RenameLegacySageIntacctExportDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Log from '@libs/Log';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';

import type {OnyxCollection, OnyxMergeCollectionInput} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';

import Onyx from 'react-native-onyx';

/**
* NewDot used to write the bare `EXPORTED` / `SUBMITTED` for the Sage Intacct export date, while the backend uses the
* `REPORT_*` names. The backend has already rewritten the stored values, but a client can still hold the old ones in
* its local Onyx cache, which match no picker row and have no translation key. This is temporary and can be removed
* once those caches have had time to refresh.
*/
const LEGACY_EXPORT_DATE_MAP: Record<string, ValueOf<typeof CONST.SAGE_INTACCT_EXPORT_DATE>> = {
EXPORTED: CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED,
SUBMITTED: CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED,
};

export default function RenameLegacySageIntacctExportDate(): Promise<void> {
return new Promise<void>((resolve) => {
const connection = Onyx.connectWithoutView({
key: ONYXKEYS.COLLECTION.POLICY,
callback: (policies: OnyxCollection<Policy>) => {
Onyx.disconnect(connection);

const updates: OnyxMergeCollectionInput<typeof ONYXKEYS.COLLECTION.POLICY> = {};
for (const policy of Object.values(policies ?? {})) {
const exportDate: string | undefined = policy?.connections?.intacct?.config?.export?.exportDate;
const newExportDate = exportDate ? LEGACY_EXPORT_DATE_MAP[exportDate] : undefined;
if (!policy?.id || !newExportDate) {
continue;
}
updates[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`] = {
connections: {intacct: {config: {export: {exportDate: newExportDate}}}},
};
}

if (Object.keys(updates).length === 0) {
Log.info('[Migrate Onyx] Skipped RenameLegacySageIntacctExportDate — no legacy values found');
return resolve();
}

// No need to add a new action just for this migration
// eslint-disable-next-line rulesdir/prefer-actions-set-data
Onyx.mergeCollection(ONYXKEYS.COLLECTION.POLICY, updates).then(() => {
Log.info(`[Migrate Onyx] Ran RenameLegacySageIntacctExportDate migration on ${Object.keys(updates).length} policies`);
resolve();
});
},
});
});
}
57 changes: 57 additions & 0 deletions tests/unit/RenameLegacySageIntacctExportDateTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import RenameLegacySageIntacctExportDate from '@libs/migrations/RenameLegacySageIntacctExportDate';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';

import Onyx from 'react-native-onyx';

import createRandomPolicy from '../utils/collections/policies';
import getOnyxValue from '../utils/getOnyxValue';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

function buildIntacctPolicy(id: number, exportDate: string): Policy {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- legacy export dates are outside the declared union, which is what the migration fixes
return {
...createRandomPolicy(id),
connections: {intacct: {config: {export: {exportDate, exporter: 'admin@example.com'}}}},
} as Policy;
}

describe('RenameLegacySageIntacctExportDate', () => {
beforeAll(() => Onyx.init({keys: ONYXKEYS}));
beforeEach(() => Onyx.clear().then(waitForBatchedUpdates));

it.each([
['EXPORTED', CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_EXPORTED],
['SUBMITTED', CONST.SAGE_INTACCT_EXPORT_DATE.REPORT_SUBMITTED],
])('rewrites a cached legacy %s export date to %s', async (legacyValue, expected) => {
// Given a policy cached before the backend migrated its Sage Intacct export date
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}1`, buildIntacctPolicy(1, legacyValue));

// When the migration runs at startup
await RenameLegacySageIntacctExportDate();
await waitForBatchedUpdates();

// Then the export date matches a picker row, and the rest of the export config is untouched
const policy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}1`);
expect(policy?.connections?.intacct?.config?.export?.exportDate).toBe(expected);
expect(policy?.connections?.intacct?.config?.export?.exporter).toBe('admin@example.com');
});

it('leaves current values and policies without Sage Intacct alone', async () => {
// Given one policy already on a current value and one with no Sage Intacct connection
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}1`, buildIntacctPolicy(1, CONST.SAGE_INTACCT_EXPORT_DATE.LAST_EXPENSE));
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}2`, createRandomPolicy(2));

// When the migration runs
await RenameLegacySageIntacctExportDate();
await waitForBatchedUpdates();

// Then neither policy gains or changes an export date
const currentPolicy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}1`);
const otherPolicy = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}2`);
expect(currentPolicy?.connections?.intacct?.config?.export?.exportDate).toBe(CONST.SAGE_INTACCT_EXPORT_DATE.LAST_EXPENSE);
expect(otherPolicy?.connections?.intacct).toBeUndefined();
});
});
Loading