File size: 3,569 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
import chai, { expect } from 'chai'
import sinon from 'sinon'
import chaiAsPromised from 'chai-as-promised'
import BaseResource from './base-resource.js'
import NotImplementedError from '../../utils/errors/not-implemented-error.js'
import Filter from '../../utils/filter/filter.js'
import BaseRecord from '../record/base-record.js'
import AdminJS from '../../../adminjs.js'
import ResourceDecorator from '../../decorators/resource/resource-decorator.js'
chai.use(chaiAsPromised)
describe('BaseResource', function () {
let resource: BaseResource
beforeEach(function () {
resource = new BaseResource({})
})
afterEach(function () {
sinon.restore()
})
describe('.isAdapterFor', function () {
it('throws NotImplementedError', async function () {
expect(() => BaseResource.isAdapterFor({})).to.throw(NotImplementedError)
})
})
describe('#databaseName', function () {
it('throws NotImplementedError', async function () {
expect(() => resource.databaseName()).to.throw(NotImplementedError)
})
})
describe('#databaseType', function () {
it('returns "database" by default', async function () {
expect(resource.databaseType()).to.eq('other')
})
})
describe('#id', function () {
it('throws NotImplementedError', async function () {
expect(() => resource.id()).to.throw(NotImplementedError)
})
})
describe('#properties', function () {
it('throws NotImplementedError', async function () {
expect(() => resource.properties()).to.throw(NotImplementedError)
})
})
describe('#property', function () {
it('throws NotImplementedError', async function () {
expect(() => resource.property('someProperty')).to.throw(NotImplementedError)
})
})
describe('#count', function () {
it('throws NotImplementedError', async function () {
expect(resource.count({} as Filter)).to.be.rejectedWith(NotImplementedError)
})
})
describe('#find', function () {
it('throws NotImplementedError', async function () {
expect(resource.find({} as Filter, {})).to.be.rejectedWith(NotImplementedError)
})
})
describe('#findOne', function () {
it('throws NotImplementedError', async function () {
expect(resource.findOne('someId')).to.be.rejectedWith(NotImplementedError)
})
})
describe('#build', function () {
it('returns new BaseRecord', async function () {
const params = { param: 'value' }
expect(resource.build(params)).to.be.instanceOf(BaseRecord)
})
})
describe('#create', function () {
it('throws NotImplementedError', async function () {
expect(resource.create({})).to.be.rejectedWith(NotImplementedError)
})
})
describe('#update', function () {
it('throws NotImplementedError', async function () {
expect(resource.update('id', {})).to.be.rejectedWith(NotImplementedError)
})
})
describe('#delete', function () {
it('throws NotImplementedError', async function () {
expect(resource.delete('id')).to.be.rejectedWith(NotImplementedError)
})
})
describe('#decorate', function () {
it('returns new Decorator when resource has been decorated', function () {
sinon.stub(resource, 'properties').returns([])
resource.assignDecorator(new AdminJS(), {})
expect(resource.decorate()).to.be.instanceOf(ResourceDecorator)
})
it('throws error when resource has not been decorated', function () {
expect(() => resource.decorate()).to.throw('resource does not have any assigned decorator yet')
})
})
})
|