Skip to content

Commit

Permalink
chore: Support migration payload contract tests. (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Aug 30, 2023
1 parent ee4ebbf commit 760567d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ function getExecution(order) {
}
}

function makeMigrationPostOptions(payload) {
if (payload) {
return { body: payload };
}
return {};
}

export async function newSdkClientEntity(options) {
const c = {};
const log = Log(options.tag);
Expand Down Expand Up @@ -170,33 +177,45 @@ export async function newSdkClientEntity(options) {
latencyTracking: migrationOperation.trackLatency,
errorTracking: migrationOperation.trackErrors,
check: migrationOperation.trackConsistency ? (a, b) => a === b : undefined,
readNew: async () => {
readNew: async (payload) => {
try {
const res = await got.post(migrationOperation.newEndpoint, {});
const res = await got.post(
migrationOperation.newEndpoint,
makeMigrationPostOptions(payload),
);
return LDMigrationSuccess(res.body);
} catch (err) {
return LDMigrationError(err.message);
}
},
writeNew: async () => {
writeNew: async (payload) => {
try {
const res = await got.post(migrationOperation.newEndpoint, {});
const res = await got.post(
migrationOperation.newEndpoint,
makeMigrationPostOptions(payload),
);
return LDMigrationSuccess(res.body);
} catch (err) {
return LDMigrationError(err.message);
}
},
readOld: async () => {
readOld: async (payload) => {
try {
const res = await got.post(migrationOperation.oldEndpoint, {});
const res = await got.post(
migrationOperation.oldEndpoint,
makeMigrationPostOptions(payload),
);
return LDMigrationSuccess(res.body);
} catch (err) {
return LDMigrationError(err.message);
}
},
writeOld: async () => {
writeOld: async (payload) => {
try {
const res = await got.post(migrationOperation.oldEndpoint, {});
const res = await got.post(
migrationOperation.oldEndpoint,
makeMigrationPostOptions(payload),
);
return LDMigrationSuccess(res.body);
} catch (err) {
return LDMigrationError(err.message);
Expand All @@ -210,6 +229,7 @@ export async function newSdkClientEntity(options) {
migrationOperation.key,
migrationOperation.context,
migrationOperation.defaultStage,
migrationOperation.payload,
);
if (res.success) {
return { result: res.result };
Expand All @@ -222,6 +242,7 @@ export async function newSdkClientEntity(options) {
migrationOperation.key,
migrationOperation.context,
migrationOperation.defaultStage,
migrationOperation.payload,
);

if (res.authoritative.success) {
Expand Down

0 comments on commit 760567d

Please sign in to comment.