Skip to content
Merged

Noop #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "functional-models-orm",
"version": "2.1.12",
"version": "2.1.13",
"description": "A basic ORM building library using the functional-models library.",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -66,6 +66,7 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.0",
"@types/chai-as-promised": "^7.1.8",
"@types/lodash": "^4.14.177",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.7",
Expand All @@ -74,6 +75,7 @@
"@typescript-eslint/parser": "^6.3.0",
"babel-eslint": "^10.1.0",
"chai": "^4.3.0",
"chai-as-promised": "^7.1.2",
"cucumber": "^6.0.7",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.46.0",
Expand All @@ -83,12 +85,13 @@
"eslint-plugin-import": "^2.28.0",
"mocha": "^10.4.0",
"nodemon": "^3.1.0",
"nyc": "^15.1.0",
"nyc": "^17.1.0",
"prettier": "^3.2.5",
"proxyquire": "^2.1.3",
"sinon": "^11.1.2",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
},
"homepage": "https://github.com/monolithst/functional-models-orm#readme",
Expand Down
29 changes: 29 additions & 0 deletions src/datastore/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DatastoreProvider } from '../interfaces'

const create = (): DatastoreProvider => {
return {
save: () => {
return Promise.reject('Cannot run save in noop')
},
delete: () => {
return Promise.reject('Cannot run delete in noop')
},
retrieve: () => {
return Promise.reject('Cannot run retrieve in noop')
},
search: () => {
return Promise.reject('Cannot run search in noop')
},
bulkInsert: () => {
return Promise.reject('Cannot run bulkInsert in noop')
},
createAndSave: () => {
return Promise.reject('Cannot run createAndSave in noop')
},
count: () => {
return Promise.reject('Cannot run count in noop')
},
}
}

export { create }
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import * as interfaces from './interfaces'
export * from './ormQuery'
export * from './interfaces'
export * from './properties'
export { create as createNoopDatastoreProvider } from './datastore/noop'

export { interfaces, orm, ormQuery, datastore, validation, properties }
68 changes: 68 additions & 0 deletions test/src/noop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { assert } from 'chai'
import chai from 'chai'
import { create } from '../../src/datastore/noop'

import asPromised from 'chai-as-promised'
// @ts-ignore
chai.use(asPromised)

describe('/src/datastore/noop.ts', () => {
describe('#create()', () => {
describe('#search()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.search({})
return assert.isRejected(promise, 'Cannot run search in noop')
})
})
describe('#save()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.save({})
return assert.isRejected(promise, 'Cannot run save in noop')
})
})
describe('#delete()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.delete({})
return assert.isRejected(promise, 'Cannot run delete in noop')
})
})
describe('#retrieve()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.retrieve({})
return assert.isRejected(promise, 'Cannot run retrieve in noop')
})
})
describe('#createAndSave()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.createAndSave({})
return assert.isRejected(promise, 'Cannot run createAndSave in noop')
})
})
describe('#bulkInsert()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.bulkInsert({})
return assert.isRejected(promise, 'Cannot run bulkInsert in noop')
})
})
describe('#count()', () => {
it('should reject the promise with the expected exception', () => {
const instance = create()
// @ts-ignore
const promise = instance.count()
return assert.isRejected(promise, 'Cannot run count in noop')
})
})
})
})
Loading