Skip to content

Commit

Permalink
test: modify tests for _rev
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Nov 18, 2019
1 parent bde072d commit bd99321
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export const CLOUDANT_CONFIG: DataSourceOptions = {
port: process.env.CLOUDANT_PORT || 8080,
username: process.env.CLOUDANT_USER || 'admin',
password: process.env.CLOUDANT_PASSWORD || 'pass',
database: process.env.CLOUDANT_DATABASE || 'testdb',
database: process.env.CLOUDANT_DATABASE || 'repository_tests',
url: process.env.CLOUDANT_URL || 'http://localhost:8080',
};

export const CLOUDANT_FEATURES: Partial<CrudFeatures> = {
idType: 'string',
supportsTransactions: false,
revisionTokenRequired: true,
};
1 change: 1 addition & 0 deletions packages/repository-tests/src/crud-test-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function crudRepositoryTestSuite(
emptyValue: undefined,
supportsTransactions: true,
supportsInclusionResolvers: true,
revisionTokenRequired: false,
...partialFeatures,
};

Expand Down
28 changes: 22 additions & 6 deletions packages/repository-tests/src/crud/replace-by-id.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ export function createSuiteForReplaceById(
await repo.replaceById(created.id, created);

const found = await repo.findById(created.id);
// use containDeep instead of deepEqual because cloudant changes _rev value after
// replacement
expect(toJSON(found)).to.containDeep(
// For revision token required connectors, the value of _rev gets changed
// the _rev value varies based on the flag `revisionTokenRequired`
let revisionToken;
if (features.revisionTokenRequired) {
revisionToken = found._rev;
} else {
revisionToken = features.emptyValue;
}

expect(toJSON(found)).to.deepEqual(
toJSON({
id: created.id,
_rev: revisionToken,
name: 'new name',
description: features.emptyValue,
}),
Expand All @@ -107,11 +115,19 @@ export function createSuiteForReplaceById(
await repo.replaceById(created.id, created);

const found = await repo.findById(created.id);
// use containDeep instead of deepEqual because cloudant changes _rev value after
// replacement
expect(toJSON(found)).to.containDeep(
// For revision token required connectors, the value of _rev gets changed
// the _rev value varies based on the flag `revisionTokenRequired`
let revisionToken;
if (features.revisionTokenRequired) {
revisionToken = found._rev;
} else {
revisionToken = features.emptyValue;
}

expect(toJSON(found)).to.deepEqual(
toJSON({
id: created.id,
_rev: revisionToken,
name: 'new name',
description: features.emptyValue,
}),
Expand Down
8 changes: 8 additions & 0 deletions packages/repository-tests/src/types.repository-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export interface CrudFeatures {
* Default: `true`
*/
supportsInclusionResolvers: boolean;

/**
* Does the connector require the revision token for replacement operations?
* (Cloudant)
*
* Default: `false`
*/
revisionTokenRequired: boolean;
}

/**
Expand Down

0 comments on commit bd99321

Please sign in to comment.