-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add types for realm * export `ConnectionOptions` * test: realm types (#1) * add test cases * move tsc option to tsconfig.json Co-authored-by: dengruoqi <[email protected]> Co-authored-by: Chen Yangjian <[email protected]>
- Loading branch information
1 parent
9b31605
commit a003599
Showing
3 changed files
with
87 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { strict as assert } from 'assert'; | ||
import Realm from '../..'; | ||
|
||
describe('=> Realm (TypeScript)', function () { | ||
let realm: Realm; | ||
before(function() { | ||
realm = new Realm({ | ||
port: process.env.MYSQL_PORT, | ||
database: 'leoric', | ||
subclass: true, | ||
}); | ||
}); | ||
|
||
describe('realm.define(name, attributes, options, descriptors)', async function() { | ||
it('options and descriptors should be optional', async function() { | ||
assert.doesNotThrow(function() { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }); | ||
}); | ||
}); | ||
|
||
it('can customize attributes with descriptors', async function() { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }, {}, { | ||
get name() { | ||
return this.attribute('name').replace(/^([a-z])/, function(m, chr) { | ||
return chr.toUpperCase(); | ||
}); | ||
}, | ||
set name(value) { | ||
if (typeof value !== 'string') throw new Error('unexpected name' + value); | ||
this.attribute('name', value); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('realm.sync(options)', async function() { | ||
it('options should be optional', async function() { | ||
assert.doesNotThrow(async () => { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }); | ||
await realm.sync(); | ||
}); | ||
}); | ||
|
||
it('`force` can be passed individually', async function() { | ||
assert.doesNotThrow(async () => { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }); | ||
await realm.sync({ force: true }); | ||
}); | ||
}); | ||
|
||
it('`alter` can be passed individually', async function() { | ||
assert.doesNotThrow(async () => { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }); | ||
await realm.sync({ alter: true }); | ||
}); | ||
}); | ||
|
||
it('`force` and `alter` can be passed together', async function() { | ||
assert.doesNotThrow(async () => { | ||
const { STRING } = realm.DataTypes; | ||
realm.define('User', { name: STRING }); | ||
await realm.sync({ force: true, alter: true }); | ||
}); | ||
}); | ||
}); | ||
}); |
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