From 381a1dbf8c0bd3a89eda9fa8621eb72cfa2c4994 Mon Sep 17 00:00:00 2001 From: radex Date: Fri, 7 May 2021 09:15:12 +0200 Subject: [PATCH] Get rid of actionsEnabled: in tests & docs --- .../Advanced/SharingDatabaseAcrossTargets.md | 34 ++++++++-------- docs-master/Components.md | 1 - docs-master/Setup.md | 1 - src/Collection/test.js | 8 ++-- src/Database/CollectionMap/test.js | 10 ++--- src/Database/index.d.ts | 3 +- src/Database/test.js | 38 +++++++++--------- src/DatabaseProvider/test.js | 2 +- src/Model/test.js | 7 ++-- src/Query/test.js | 10 ++--- src/__tests__/testModels.js | 3 -- src/decorators/action/test.js | 6 +-- src/decorators/children/test.js | 1 - src/decorators/nochange/test.js | 1 - src/hooks/test.js | 2 +- src/observation/subscribeToCount/test.js | 2 +- .../subscribeToQueryReloading/test.js | 4 +- .../subscribeToQueryWithColumns/test.js | 4 +- src/sync/test.js | 39 +++++++------------ 19 files changed, 76 insertions(+), 100 deletions(-) diff --git a/docs-master/Advanced/SharingDatabaseAcrossTargets.md b/docs-master/Advanced/SharingDatabaseAcrossTargets.md index d5a09bcbe..a65b3a4c5 100644 --- a/docs-master/Advanced/SharingDatabaseAcrossTargets.md +++ b/docs-master/Advanced/SharingDatabaseAcrossTargets.md @@ -37,30 +37,29 @@ This tells iOS to share storage directories between your targets, and in this ca import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite'; import schema from './schema'; import RNFetchBlob from 'rn-fetch-blob'; - + const getAppGroupPath = (): string => { let path = ''; - + if (Platform.OS === 'ios') { path = `${RNFetchBlob.fs.syncPathAppGroup('group.com.example.MyAwesomeApp')}/`; } - + return path; } - + const adapter = new SQLiteAdapter({ dbName: `${getAppGroupPath()}default.db`, schema, }); - + const database = new Database({ adapter, modelClasses: [ ... ], - actionsEnabled: true, }); - + export default database; ``` @@ -80,10 +79,10 @@ This tells iOS to share storage directories between your targets, and in this ca 4. Add a file named `AppGroup.swift` and paste the following: ``` import Foundation - + @objc(AppGroup) class AppGroup: NSObject { - + @objc func constantsToExport() -> [AnyHashable : Any]! { var path = "" @@ -92,13 +91,13 @@ This tells iOS to share storage directories between your targets, and in this ca path = directory.path } } - + return ["path": "\(path)/"] } } ``` This reads your new `Info.plist` row and exports a constant called `path` with your App Group path (shared directory path), to be used in your JS code. - + 5. In your JS, when creating the database, import the `path` constant from your new `AppGroup` module and prepend to your `dbName`: ```ts @@ -106,30 +105,29 @@ This tells iOS to share storage directories between your targets, and in this ca import { Database } from '@nozbe/watermelondb'; import SQLiteAdapter from '@nozbe/watermelondb/adapters/sqlite'; import schema from './schema'; - + const getAppGroupPath = (): string => { let path = ''; - + if (Platform.OS === 'ios') { path = NativeModules.AppGroup.path; } - + return path; } - + const adapter = new SQLiteAdapter({ dbName: `${getAppGroupPath()}default.db`, schema, }); - + const database = new Database({ adapter, modelClasses: [ ... ], - actionsEnabled: true, }); - + export default database; ``` diff --git a/docs-master/Components.md b/docs-master/Components.md index 391a41a42..a6b78d525 100644 --- a/docs-master/Components.md +++ b/docs-master/Components.md @@ -252,7 +252,6 @@ import DatabaseProvider from '@nozbe/watermelondb/DatabaseProvider' const database = new Database({ adapter, modelClasses: [Blog, Post, Comment], - actionsEnabled: true, }) render( diff --git a/docs-master/Setup.md b/docs-master/Setup.md index 6a0d56f7d..378930714 100644 --- a/docs-master/Setup.md +++ b/docs-master/Setup.md @@ -60,7 +60,6 @@ const database = new Database({ modelClasses: [ // Post, // ⬅️ You'll add Models to Watermelon here ], - actionsEnabled: true, }) ``` diff --git a/src/Collection/test.js b/src/Collection/test.js index 6a47bf975..0cac9c274 100644 --- a/src/Collection/test.js +++ b/src/Collection/test.js @@ -238,7 +238,7 @@ describe('creating new records', () => { expect(newModelSpy).toHaveBeenCalledTimes(1) }) it('disallows record creating outside of an action', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() await expectToRejectWithMessage( tasks.create(noop), @@ -252,7 +252,7 @@ describe('creating new records', () => { describe('Collection observation', () => { it('can subscribe to collection changes', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() await database.action(() => tasks.create()) @@ -289,7 +289,7 @@ describe('Collection observation', () => { expect(subscriber2).toHaveBeenCalledTimes(2) }) it('unsubscribe can safely be called more than once', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const subscriber1 = jest.fn() const unsubscribe1 = tasks.experimentalSubscribe(subscriber1) @@ -305,7 +305,7 @@ describe('Collection observation', () => { unsubscribe1() }) it(`can subscribe with the same subscriber multiple times`, async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const trigger = () => database.action(() => tasks.create()) const subscriber = jest.fn() diff --git a/src/Database/CollectionMap/test.js b/src/Database/CollectionMap/test.js index 994f3db63..8c60c35b3 100644 --- a/src/Database/CollectionMap/test.js +++ b/src/Database/CollectionMap/test.js @@ -4,7 +4,7 @@ import Model from '../../Model' describe('CollectionMap', () => { it('can initialize and get models', () => { - const { db } = mockDatabase({ actionsEnabled: true }) + const { db } = mockDatabase() const map = new CollectionMap(db, [MockProject, MockTask]) expect(map.get('mock_projects').modelClass).toBe(MockProject) @@ -13,14 +13,14 @@ describe('CollectionMap', () => { expect(map.get('mock_tasks').table).toBe('mock_tasks') }) it(`returns null for collections that don't exist`, () => { - const { db } = mockDatabase({ actionsEnabled: true }) + const { db } = mockDatabase() const map = new CollectionMap(db, [MockProject, MockTask]) expect(map.get('mock_comments')).toBe(null) expect(map.get('does_not_exist')).toBe(null) }) it(`returns null for naughty table names`, () => { - const { db } = mockDatabase({ actionsEnabled: true }) + const { db } = mockDatabase() const map = new CollectionMap(db, [MockProject, MockTask]) expect(map.get(null)).toBe(null) @@ -30,14 +30,14 @@ describe('CollectionMap', () => { expect(map.get('hasOwnProperty')).toBe(null) }) it(`collection map is immutable`, () => { - const { db } = mockDatabase({ actionsEnabled: true }) + const { db } = mockDatabase() const map = new CollectionMap(db, [MockProject, MockTask]) expect(() => { map.map.foo = 'hey' }).toThrow() }) it(`alerts the user of invalid model classes`, () => { - const { db } = mockDatabase({ actionsEnabled: true }) + const { db } = mockDatabase() class ModelWithMissingTable extends Model {} expect(() => new CollectionMap(db, [ModelWithMissingTable])).toThrow( /Model class ModelWithMissingTable passed to Database constructor is missing "static table = 'table_name'"/, diff --git a/src/Database/index.d.ts b/src/Database/index.d.ts index 314a8ca87..9aea1feac 100644 --- a/src/Database/index.d.ts +++ b/src/Database/index.d.ts @@ -19,7 +19,6 @@ declare module '@nozbe/watermelondb/Database' { options: { adapter: DatabaseAdapter; modelClasses: Class[]; - actionsEnabled: boolean; }) public batch(...records: (Model | null | void | false | Promise)[]): Promise @@ -32,7 +31,7 @@ declare module '@nozbe/watermelondb/Database' { ): Observable | null> public unsafeResetDatabase(): Promise - + public get(tableName: TableName): Collection } } diff --git a/src/Database/test.js b/src/Database/test.js index 7f385f6dc..e03d7aefd 100644 --- a/src/Database/test.js +++ b/src/Database/test.js @@ -6,7 +6,7 @@ import * as Q from '../QueryDescription' describe('Database', () => { it(`implements get()`, () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() expect(database.get('mock_tasks').table).toBe('mock_tasks') expect(database.get('mock_tasks')).toBe(database.collections.get('mock_tasks')) expect(database.get('mock_comments')).toBe(database.collections.get('mock_comments')) @@ -14,7 +14,7 @@ describe('Database', () => { describe('unsafeResetDatabase', () => { it('can reset database', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const m1 = await database.action(() => tasks.create()) const m2 = await database.action(() => tasks.create()) @@ -29,7 +29,7 @@ describe('Database', () => { await expectToRejectWithMessage(tasks.find(m2.id), /not found/) }) it('throws error if reset is called from outside an Action', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const m1 = await database.action(() => tasks.create()) await expectToRejectWithMessage( @@ -40,7 +40,7 @@ describe('Database', () => { expect(await tasks.find(m1.id)).toBe(m1) }) it('increments reset count after every reset', async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() expect(database._resetCount).toBe(0) await database.action(() => database.unsafeResetDatabase()) @@ -50,7 +50,7 @@ describe('Database', () => { expect(database._resetCount).toBe(2) }) it('prevents Adapter from being called during reset db', async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() const checkAdapter = async () => { expect(await database.adapter.getLocal('test')).toBe(null) @@ -77,7 +77,7 @@ describe('Database', () => { await checkAdapter() }) it('Cancels Database experimental subscribers during reset', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() // sanity check first const subscriber1 = jest.fn() @@ -116,7 +116,7 @@ describe('Database', () => { it.skip('Cancels Relation observation during reset', async () => {}) it.skip('Cancels Relation experimental subscribers during reset', async () => {}) it('Signals internally when database is being reset', async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() expect(database._isBeingReset).toBe(false) const promise = database.action(() => database.unsafeResetDatabase()) @@ -148,7 +148,7 @@ describe('Database', () => { cloneDatabase, tasks: tasksCollection, comments: commentsCollection, - } = mockDatabase({ actionsEnabled: true }) + } = mockDatabase() const adapterBatchSpy = jest.spyOn(database.adapter, 'batch') // m1, m2 will be used to test batch-updates @@ -239,7 +239,7 @@ describe('Database', () => { expect(fetchedM4.length).toBe(0) }) it('ignores falsy values passed', async () => { - const { database, tasks: tasksCollection } = mockDatabase({ actionsEnabled: true }) + const { database, tasks: tasksCollection } = mockDatabase() const adapterBatchSpy = jest.spyOn(database.adapter, 'batch') const model = tasksCollection.prepareCreate() @@ -249,7 +249,7 @@ describe('Database', () => { expect(adapterBatchSpy).toHaveBeenLastCalledWith([['create', 'mock_tasks', model._raw]]) }) it(`can batch with an array passed as argument`, async () => { - const { database, tasks: tasksCollection } = mockDatabase({ actionsEnabled: true }) + const { database, tasks: tasksCollection } = mockDatabase() const adapterBatchSpy = jest.spyOn(database.adapter, 'batch') const model = tasksCollection.prepareCreate() @@ -259,7 +259,7 @@ describe('Database', () => { expect(adapterBatchSpy).toHaveBeenLastCalledWith([['create', 'mock_tasks', model._raw]]) }) it('throws error if attempting to batch records without a pending operation', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const m1 = await database.action(() => tasks.create()) await expectToRejectWithMessage( @@ -268,7 +268,7 @@ describe('Database', () => { ) }) it('throws error if batch is called outside of an action', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() await expectToRejectWithMessage( database.batch(tasks.prepareCreate(noop)), @@ -287,7 +287,7 @@ describe('Database', () => { expect(task.name).toBe('foo1') }) it(`throws an error if invalid arguments`, async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() await expectToRejectWithMessage( database.batch([], null), /batch should be called with a list/, @@ -297,7 +297,7 @@ describe('Database', () => { describe('Observation', () => { it('implements withChangesForTables', async () => { - const { database, projects, tasks, comments } = mockDatabase({ actionsEnabled: true }) + const { database, projects, tasks, comments } = mockDatabase() const observer = jest.fn() database.withChangesForTables(['mock_projects', 'mock_tasks']).subscribe(observer) @@ -339,7 +339,7 @@ describe('Database', () => { ]) }) it('can subscribe to change signals for particular tables', async () => { - const { database, projects, tasks, comments } = mockDatabase({ actionsEnabled: true }) + const { database, projects, tasks, comments } = mockDatabase() const subscriber1 = jest.fn() const unsubscribe1 = database.experimentalSubscribe([], subscriber1) @@ -389,7 +389,7 @@ describe('Database', () => { unsubscribe3() }) it('unsubscribe can safely be called more than once', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const subscriber1 = jest.fn() const unsubscribe1 = database.experimentalSubscribe(['mock_tasks'], subscriber1) @@ -405,7 +405,7 @@ describe('Database', () => { unsubscribe1() }) it(`can subscribe with the same subscriber multiple times`, async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const subscriber = jest.fn() const unsubscribe1 = database.experimentalSubscribe(['mock_tasks'], subscriber) @@ -426,7 +426,7 @@ describe('Database', () => { expect(subscriber).toHaveBeenCalledTimes(4) }) it('has new objects cached before calling subscribers (regression test)', async () => { - const { database, projects, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, projects, tasks } = mockDatabase() const project = projects.prepareCreate() const task = tasks.prepareCreate(t => { @@ -604,7 +604,7 @@ describe('Database', () => { expect(called2).toBe(0) }) it('aborts all pending actions if database is reset', async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() let promise1 let promise2 diff --git a/src/DatabaseProvider/test.js b/src/DatabaseProvider/test.js index fc365e6d5..dec850705 100644 --- a/src/DatabaseProvider/test.js +++ b/src/DatabaseProvider/test.js @@ -12,7 +12,7 @@ function MockComponent() { describe('DatabaseProvider', () => { let database beforeAll(() => { - database = mockDatabase({ actionsEnabled: true }).db + database = mockDatabase().db }) it('throws if no database or adapter supplied', () => { expect(() => { diff --git a/src/Model/test.js b/src/Model/test.js index cc4cac349..1445741b8 100644 --- a/src/Model/test.js +++ b/src/Model/test.js @@ -82,11 +82,10 @@ class MockModelCreatedUpdated extends Model { updatedAt } -const makeDatabase = ({ actionsEnabled = false } = {}) => +const makeDatabase = () => new Database({ adapter: { schema: mockSchema }, modelClasses: [MockModel, MockModelCreated, MockModelUpdated, MockModelCreatedUpdated], - actionsEnabled, }) describe('Model', () => { @@ -437,7 +436,7 @@ describe('Safety features', () => { database.batch(model) }) it('disallows writes outside of an action', async () => { - const database = makeDatabase({ actionsEnabled: true }) + const database = makeDatabase() database.adapter.batch = jest.fn() const model = await database.action(() => database.get('mock').create()) @@ -797,7 +796,7 @@ describe('Model observation', () => { unsubscribe1() }) it(`can subscribe with the same subscriber multiple times`, async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const task = await database.action(() => tasks.create()) const trigger = () => database.action(() => task.update()) const subscriber = jest.fn() diff --git a/src/Query/test.js b/src/Query/test.js index 601ae4427..96fc6058b 100644 --- a/src/Query/test.js +++ b/src/Query/test.js @@ -240,7 +240,7 @@ describe('Query', () => { // no test here - Collection._fetchCount is tested }) it(`is thenable`, async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const queryAll = new Query(tasks, []) const m1 = tasks.prepareCreate() const m2 = tasks.prepareCreate() @@ -249,7 +249,7 @@ describe('Query', () => { expect(await queryAll.then(records => records.length)).toBe(2) }) it(`count is thenable`, async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const queryAll = new Query(tasks, []) await database.action(() => database.batch(tasks.prepareCreate(), tasks.prepareCreate())) expect(await queryAll.count).toEqual(2) @@ -265,7 +265,7 @@ describe('Query', () => { return database.adapter.getLocal('nothing') } const testQueryObservation = async (makeSubscribe, withColumns) => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const adapterSpy = jest.spyOn(database.adapter.underlyingAdapter, 'query') const query = new Query(tasks, []) const observer = jest.fn() @@ -318,7 +318,7 @@ describe('Query', () => { }) const testCountObservation = async (makeSubscribe, isThrottled) => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const adapterSpy = jest.spyOn(database.adapter.underlyingAdapter, 'count') const query = new Query(tasks, []) const observer = jest.fn() @@ -372,7 +372,7 @@ describe('Query', () => { describe('mass delete', () => { const testMassDelete = async methodName => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const query = new Query(tasks, [Q.where('name', 'foo')]) const queryAll = new Query(tasks, []) diff --git a/src/__tests__/testModels.js b/src/__tests__/testModels.js index 1bc94aeed..3bd142846 100644 --- a/src/__tests__/testModels.js +++ b/src/__tests__/testModels.js @@ -90,7 +90,6 @@ export class MockComment extends Model { export const modelClasses = [MockProject, MockTask, MockComment] export const mockDatabase = ({ - actionsEnabled = false, schema = testSchema, migrations = undefined, } = {}) => { @@ -105,7 +104,6 @@ export const mockDatabase = ({ adapter, schema, modelClasses, - actionsEnabled, }) return { database, @@ -120,7 +118,6 @@ export const mockDatabase = ({ adapter: await database.adapter.underlyingAdapter.testClone({ schema: clonedSchema }), schema: clonedSchema, modelClasses, - actionsEnabled, }), } } diff --git a/src/decorators/action/test.js b/src/decorators/action/test.js index 4edb1a0b4..6c5c1ef61 100644 --- a/src/decorators/action/test.js +++ b/src/decorators/action/test.js @@ -15,7 +15,7 @@ class MockTaskExtended extends MockTask { describe('@action', () => { it('calls db.action() and passes arguments correctly', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const record = new MockTaskExtended(tasks, { name: 'test' }) const actionSpy = jest.spyOn(database, 'action') @@ -27,13 +27,13 @@ describe('@action', () => { expect(actionSpy.mock.calls[0][1]).toBe('mock_tasks.returnArgs') }) it('can call subactions using this.subAction', async () => { - const { tasks } = mockDatabase({ actionsEnabled: true }) + const { tasks } = mockDatabase() const record = new MockTaskExtended(tasks, { name: 'test' }) expect(await record.nested(1, 2, 3, 4)).toEqual(['test', 'sub', 1, [2, 3, 4]]) }) it('works with arbitrary classes', async () => { - const { database } = mockDatabase({ actionsEnabled: true }) + const { database } = mockDatabase() const actionSpy = jest.spyOn(database, 'action') class TestClass { database diff --git a/src/decorators/children/test.js b/src/decorators/children/test.js index 6e7c03db5..ff486d6b3 100644 --- a/src/decorators/children/test.js +++ b/src/decorators/children/test.js @@ -39,7 +39,6 @@ const makeDatabase = () => }), }, modelClasses: [MockParent, MockChild], - actionsEnabled: true, }) describe('decorators/children', () => { diff --git a/src/decorators/nochange/test.js b/src/decorators/nochange/test.js index 479bb6afb..cad069d43 100644 --- a/src/decorators/nochange/test.js +++ b/src/decorators/nochange/test.js @@ -29,7 +29,6 @@ const makeDatabase = () => }), }, modelClasses: [MockModel], - actionsEnabled: true, }) describe('decorators/nochange', () => { diff --git a/src/hooks/test.js b/src/hooks/test.js index 2cca0b23d..af59e54b5 100644 --- a/src/hooks/test.js +++ b/src/hooks/test.js @@ -13,7 +13,7 @@ import { mockDatabase } from '../__tests__/testModels' describe('useDatabase hook', () => { let database beforeAll(() => { - database = mockDatabase({ actionsEnabled: true }).db + database = mockDatabase().db }) test('should use database', () => { const wrapper = ({ children }) => ( diff --git a/src/observation/subscribeToCount/test.js b/src/observation/subscribeToCount/test.js index 0f8813183..fd62a7d7c 100644 --- a/src/observation/subscribeToCount/test.js +++ b/src/observation/subscribeToCount/test.js @@ -17,7 +17,7 @@ const updateTask = (task, updater) => task.collection.database.action(() => task describe('subscribeToCount', () => { it('observes changes to count', async () => { - const { database, tasks } = mockDatabase({ actionsEnabled: true }) + const { database, tasks } = mockDatabase() const query = tasks.query(Q.where('is_completed', true)) diff --git a/src/observation/subscribeToQueryReloading/test.js b/src/observation/subscribeToQueryReloading/test.js index e8bfd12ad..3f6eceb5e 100644 --- a/src/observation/subscribeToQueryReloading/test.js +++ b/src/observation/subscribeToQueryReloading/test.js @@ -19,7 +19,7 @@ const updateTask = (task, updater) => task.collection.database.action(() => task describe('subscribeToQueryReloading', () => { it('observes changes to query', async () => { - const { database, tasks, projects } = mockDatabase({ actionsEnabled: true }) + const { database, tasks, projects } = mockDatabase() const query = tasks.query( Q.where('is_completed', true), @@ -90,7 +90,7 @@ describe('subscribeToQueryReloading', () => { expect(observer).toHaveBeenCalledTimes(4) }) it('calls observer even if query is empty (regression)', async () => { - const { tasks } = mockDatabase({ actionsEnabled: true }) + const { tasks } = mockDatabase() const observer = jest.fn() const unsubscribe = subscribeToQueryReloading(tasks.query(), observer) diff --git a/src/observation/subscribeToQueryWithColumns/test.js b/src/observation/subscribeToQueryWithColumns/test.js index ebdf7a562..911191b88 100644 --- a/src/observation/subscribeToQueryWithColumns/test.js +++ b/src/observation/subscribeToQueryWithColumns/test.js @@ -147,12 +147,12 @@ describe('subscribeToQueryWithColumns', () => { expect(observer).toHaveBeenCalledTimes(7) } it('observes changes correctly - test with simple observer', async () => { - const mockDb = mockDatabase({ actionsEnabled: true }) + const mockDb = mockDatabase() const query = mockDb.tasks.query(Q.where('is_completed', true)) await fullObservationTest(mockDb, query, false) }) it('observes changes correctly - test with reloading observer', async () => { - const mockDb = mockDatabase({ actionsEnabled: true }) + const mockDb = mockDatabase() const query = mockDb.tasks.query( Q.where('is_completed', true), // fake query to force to use reloading observer diff --git a/src/sync/test.js b/src/sync/test.js index 8bb2d5873..df2183b81 100644 --- a/src/sync/test.js +++ b/src/sync/test.js @@ -45,7 +45,7 @@ describe('Conflict resolution', () => { }) }) -const makeDatabase = () => mockDatabase({ actionsEnabled: true }) +const makeDatabase = () => mockDatabase() const prepareCreateFromRaw = (collection, dirtyRaw) => collection.prepareCreate(record => { @@ -270,11 +270,6 @@ describe('hasUnsyncedChanges', () => { expect(await hasUnsyncedChanges({ database })).toBe(true) }) - it('aborts if actions are not enabled', async () => { - const { database } = mockDatabase({ actionsEnabled: false }) - - await expectToRejectWithMessage(hasUnsyncedChanges({ database }), /actions must be enabled/i) - }) }) describe('isChangeSetEmpty', () => { @@ -423,7 +418,7 @@ describe('markLocalChangesAsSynced', () => { sorted([newProject, tCreated, pSynced, tUpdated]), ) expect(destroyDeletedRecordsSpy).toHaveBeenCalledTimes(0) - + await expectSyncedAndMatches(tasks, 'tUpdated', { _status: 'updated', // TODO: ideally position would probably not be here @@ -441,7 +436,7 @@ describe('markLocalChangesAsSynced', () => { expect(destroyDeletedRecordsSpy).toHaveBeenCalledTimes(2) expect(destroyDeletedRecordsSpy).toHaveBeenCalledWith('mock_tasks', ['tSynced']) expect(destroyDeletedRecordsSpy).toHaveBeenCalledWith('mock_comments', ['cUpdated', 'cCreated']) - + }) // TODO: Unskip the test when batch collection emissions are implemented it.skip('only emits one collection batch change', async () => { @@ -1250,14 +1245,6 @@ describe('synchronize', () => { ) await expectToRejectWithMessage(projects.find('new_project'), /not found/) }) - it('aborts if actions are not enabled', async () => { - const { database } = mockDatabase({ actionsEnabled: false }) - - await expectToRejectWithMessage( - synchronize({ database, pullChanges: jest.fn(), pushChanges: jest.fn() }), - /actions must be enabled/i, - ) - }) describe('migration syncs', () => { const testSchema10 = { ...testSchema, version: 10 } const migrations = schemaMigrations({ @@ -1284,7 +1271,7 @@ describe('synchronize', () => { ], }) it(`remembers synced schema version on first sync`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) const pullChanges = jest.fn(emptyPull()) await synchronize({ @@ -1303,7 +1290,7 @@ describe('synchronize', () => { expect(await database.adapter.getLocal('__watermelon_last_pulled_schema_version')).toBe('10') }) it(`remembers synced schema version on first sync, even if migrations are not enabled`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10 }) + const { database } = mockDatabase({ schema: testSchema10 }) const pullChanges = jest.fn(emptyPull()) await synchronize({ database, pullChanges, pushChanges: jest.fn() }) @@ -1315,7 +1302,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(10) }) it(`does not remember schema version if migration syncs are not enabled`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10 }) + const { database } = mockDatabase({ schema: testSchema10 }) await setLastPulledAt(database, 100) const pullChanges = jest.fn(emptyPull()) @@ -1328,7 +1315,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(null) }) it(`performs no migration if up to date`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await setLastPulledAt(database, 1500) await setLastPulledSchemaVersion(database, 10) @@ -1347,7 +1334,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(10) }) it(`performs migration sync on schema version bump`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await setLastPulledAt(database, 1500) await setLastPulledSchemaVersion(database, 9) @@ -1370,7 +1357,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(10) }) it(`performs fallback migration sync`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await setLastPulledAt(database, 1500) const pullChanges = jest.fn(emptyPull(2500)) @@ -1392,7 +1379,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(10) }) it(`does not remember schema version if pull fails`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await synchronize({ database, pullChanges: jest.fn(() => Promise.reject(new Error('pull-fail'))), @@ -1402,7 +1389,7 @@ describe('synchronize', () => { expect(await getLastPulledSchemaVersion(database)).toBe(null) }) it(`fails on programmer errors`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await expectToRejectWithMessage( synchronize({ database, migrationsEnabledAtVersion: '9' }), @@ -1414,7 +1401,7 @@ describe('synchronize', () => { ) await expectToRejectWithMessage( synchronize({ - database: mockDatabase({ actionsEnabled: true, schema: testSchema10 }).db, + database: mockDatabase({ schema: testSchema10 }).db, migrationsEnabledAtVersion: 9, }), 'Migration syncs cannot be enabled on a database that does not support migrations', @@ -1425,7 +1412,7 @@ describe('synchronize', () => { ) }) it(`fails on last synced schema version > current schema version`, async () => { - const { database } = mockDatabase({ actionsEnabled: true, schema: testSchema10, migrations }) + const { database } = mockDatabase({ schema: testSchema10, migrations }) await setLastPulledAt(database, 1500) await setLastPulledSchemaVersion(database, 11) await expectToRejectWithMessage(