diff --git a/acceptance/repository-cloudant/src/__tests__/cloudant.datasource.ts b/acceptance/repository-cloudant/src/__tests__/cloudant.datasource.ts index 3fe6f8147ed2..973816b8bb68 100644 --- a/acceptance/repository-cloudant/src/__tests__/cloudant.datasource.ts +++ b/acceptance/repository-cloudant/src/__tests__/cloudant.datasource.ts @@ -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 = { idType: 'string', supportsTransactions: false, + revisionTokenRequired: true, }; diff --git a/packages/repository-tests/src/crud-test-suite.ts b/packages/repository-tests/src/crud-test-suite.ts index 057edd762fc5..b1dbdff69cae 100644 --- a/packages/repository-tests/src/crud-test-suite.ts +++ b/packages/repository-tests/src/crud-test-suite.ts @@ -34,6 +34,7 @@ export function crudRepositoryTestSuite( emptyValue: undefined, supportsTransactions: true, supportsInclusionResolvers: true, + revisionTokenRequired: false, ...partialFeatures, }; diff --git a/packages/repository-tests/src/crud/replace-by-id.suite.ts b/packages/repository-tests/src/crud/replace-by-id.suite.ts index 722d23b4c5d0..1ffed64010d0 100644 --- a/packages/repository-tests/src/crud/replace-by-id.suite.ts +++ b/packages/repository-tests/src/crud/replace-by-id.suite.ts @@ -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, }), @@ -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, }), diff --git a/packages/repository-tests/src/types.repository-tests.ts b/packages/repository-tests/src/types.repository-tests.ts index c41e335a53be..c9d0eb93b36d 100644 --- a/packages/repository-tests/src/types.repository-tests.ts +++ b/packages/repository-tests/src/types.repository-tests.ts @@ -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; } /**