Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for payloads to read and write methods. #215

Merged
merged 1 commit into from
Jul 28, 2023
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
49 changes: 43 additions & 6 deletions packages/shared/sdk-server/__tests__/Migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('given an LDClient with test data', () => {
[new LDSerialExecution(LDExecutionOrdering.Random), 'serial random'],
[new LDConcurrentExecution(), 'concurrent'],
])('given different execution methods: %p %p', (execution) => {
it.each([
describe.each([
[
LDMigrationStage.Off,
'old',
Expand Down Expand Up @@ -172,9 +172,8 @@ describe('given an LDClient with test data', () => {
nonAuthoritative: undefined,
},
],
])(
'uses the correct authoritative source: %p, read: %p, write: %j.',
async (stage, readValue, writeMatch) => {
])('given each migration step: %p, read: %p, write: %j.', (stage, readValue, writeMatch) => {
it('uses the correct authoritative source', async () => {
const migration = new Migration<string, boolean>(client, {
execution,
latencyTracking: LDLatencyTracking.Disabled,
Expand Down Expand Up @@ -202,8 +201,46 @@ describe('given an LDClient with test data', () => {
const write = await migration.write(flagKey, { key: 'test-key' }, defaultStage!);
// @ts-ignore Extended without writing types.
expect(write).toMatchMigrationResult(writeMatch);
}
);
});

it('correctly forwards the payload for read and write operations', async () => {
let receivedReadPayload: string | undefined;
let receivedWritePayload: string | undefined;
const migration = new Migration<string, boolean, string, string>(client, {
execution,
latencyTracking: LDLatencyTracking.Disabled,
errorTracking: LDErrorTracking.Disabled,
readNew: async (payload) => {
receivedReadPayload = payload;
return LDMigrationSuccess('new');
},
writeNew: async (payload) => {
receivedWritePayload = payload;
return LDMigrationSuccess(false);
},
readOld: async (payload) => {
receivedReadPayload = payload;
return LDMigrationSuccess('old');
},
writeOld: async (payload) => {
receivedWritePayload = payload;
return LDMigrationSuccess(true);
},
});

const flagKey = 'migration';
td.update(td.flag(flagKey).valueForAll(stage));

const payloadRead = Math.random().toString(10);
const payloadWrite = Math.random().toString(10);
await migration.read(flagKey, { key: 'test-key' }, LDMigrationStage.Off, payloadRead);

await migration.write(flagKey, { key: 'test-key' }, LDMigrationStage.Off, payloadWrite);

expect(receivedReadPayload).toEqual(payloadRead);
expect(receivedWritePayload).toEqual(payloadWrite);
});
});
});

it.each([
Expand Down
Loading