https://github.com/avh4/dropbox-mock.js
Test double for Dropbox API
https://github.com/avh4/dropbox-mock.js
Last synced: 3 months ago
JSON representation
Test double for Dropbox API
- Host: GitHub
- URL: https://github.com/avh4/dropbox-mock.js
- Owner: avh4
- License: mit
- Created: 2014-06-02T00:56:27.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-16T01:30:43.000Z (almost 11 years ago)
- Last Synced: 2025-03-08T10:47:25.210Z (4 months ago)
- Language: JavaScript
- Size: 318 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](http://travis-ci.org/avh4/dropbox-mock.js)
[](http://nodejs.org/api/documentation.html#documentation_stability_index)## Usage
```bash
npm install --save-dev dropbox-mock
```Global test setup:
```javascript
global.Dropbox = new (require('dropbox-mock'))();
global.Dropbox.allowAppKey('FAKE-KEY-FOR-TEST');
```When creating the Dropbox Client in test, you need to use the same app key that you allowed in the global test setup above.
```javascript
new Dropbox.Client({key: 'FAKE-KEY-FOR-TEST'});
```After exercising code that should have created records, you can inspect the fake Dropbox datastore:
```javascript
global.Dropbox['MyTable']; // => yields the stored object
```## Currently supported APIs
- `new Dropbox.Client`
- `Client.authenticate()`
- `Client.isAuthenticated()`
- `Client.getDatastoreManager()`
- `DatatstoreManager.openDefaultDatastore(callback)`
- `Datastore.getTable(name)`
- `Datastore.recordsChanged.addListener(callback)` (must be manually triggered by your test)
- `Table.query()` (no params)
- `Table.insert(record)`
- `Record.get(fieldName)`
- `Record.deleteRecord()`
- `Record.getId()`
- `Record.update()`Pull requests are welcome.
## Examples
### Table.query()
```javascript
global.Dropbox = new (require('dropbox-mock'))();
global.Dropbox.allowAppKey('FAKE-KEY-FOR-TEST');
global.Dropbox['MyTable'] = [ { name: "Record 1", value: 1 } ];
// call subject method that queries MyTable
```### Table.insert(record)
```javascript
global.Dropbox = new (require('dropbox-mock'))();
global.Dropbox.allowAppKey('FAKE-KEY-FOR-TEST');
// call subject method that should insert records
expect(global.Dropbox['MyTable']).to.equal(expectedRecords);
```### Datastore.recordsChanged.addListener(callback)
```javascript
global.Dropbox = new (require('dropbox-mock'))();
global.Dropbox.allowAppKey('FAKE-KEY-FOR-TEST');
// call subject method that should register a listener
global.Dropbox.triggerRecordsChanged();
// verify subject performed an action in response to a recordsChanged event
```