-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add docKeys and getProps/getDocument to BaseEntity
- Loading branch information
Showing
10 changed files
with
251 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ export default interface ProtoData { | |
*/ | ||
fields: { | ||
key: string | ||
docKey: string | ||
}[] | ||
|
||
views: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import PouchDB from 'pouchdb' | ||
import { | ||
SlothDatabase, | ||
SlothURI, | ||
BaseEntity, | ||
SlothEntity, | ||
SlothField | ||
} from '../../src/slothdb' | ||
|
||
PouchDB.plugin(require('pouchdb-adapter-memory')) | ||
|
||
describe('docKeys', () => { | ||
let prefix: string | ||
|
||
const factory = (pre: string) => (name: string) => | ||
new PouchDB(pre + name, { adapter: 'memory' }) | ||
|
||
interface IFoo { | ||
_id: string | ||
name: string | ||
bar: string | ||
} | ||
|
||
@SlothEntity('foos') | ||
class FooEntity extends BaseEntity<IFoo> { | ||
@SlothURI('foos', 'name', 'bar') | ||
_id: string | ||
@SlothField() name: string | ||
@SlothField('barz') bar: string | ||
} | ||
|
||
const Foo = new SlothDatabase<IFoo, FooEntity>(FooEntity) | ||
|
||
beforeEach(() => { | ||
prefix = '__' + Date.now().toString(16) + '_' | ||
}) | ||
|
||
test('getProps maps props', () => { | ||
const doc = Foo.create(factory(prefix), { name: 'Foo Bar', bar: 'barz' }) | ||
|
||
expect(doc.getProps()).toEqual({ | ||
_id: 'foos/foo-bar/barz', | ||
name: 'Foo Bar', | ||
bar: 'barz' | ||
}) | ||
}) | ||
|
||
test('getProps maps props from doc', () => { | ||
const doc = Foo.create(factory(prefix), { | ||
name: 'Foo Bar', | ||
barz: 'barz' | ||
} as any) | ||
|
||
expect(doc.getProps()).toEqual({ | ||
_id: 'foos/foo-bar/barz', | ||
name: 'Foo Bar', | ||
bar: 'barz' | ||
}) | ||
}) | ||
|
||
test('getDocument maps document', () => { | ||
const doc = Foo.create(factory(prefix), { name: 'Foo Bar', bar: 'barz' }) | ||
|
||
expect(doc.getDocument()).toEqual({ | ||
_id: 'foos/foo-bar/barz', | ||
name: 'Foo Bar', | ||
barz: 'barz' | ||
}) | ||
}) | ||
|
||
test('getDocument maps document from doc', () => { | ||
const doc = Foo.create(factory(prefix), { | ||
name: 'Foo Bar', | ||
barz: 'barz' | ||
} as any) | ||
|
||
expect(doc.getDocument()).toEqual({ | ||
_id: 'foos/foo-bar/barz', | ||
name: 'Foo Bar', | ||
barz: 'barz' | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.