Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2eabc2a
commit 68c503e
Showing
2 changed files
with
123 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { module, test } from 'qunit'; | ||
import Server from 'ember-cli-mirage/server'; | ||
import { Model, hasMany, belongsTo } from 'ember-cli-mirage'; | ||
|
||
module('Integration | ORM | assertions', function(hooks) { | ||
|
||
hooks.beforeEach(function() { | ||
this.server = new Server({ | ||
models: { | ||
user: Model.extend({ | ||
posts: hasMany() | ||
}), | ||
post: Model.extend({ | ||
author: belongsTo('user') | ||
}) | ||
} | ||
}); | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
this.server.shutdown(); | ||
}); | ||
|
||
test('it errors when passing in the wrong type for a HasMany association', function(assert) { | ||
assert.throws(() => { | ||
this.server.schema.users.create({ | ||
name: 'Sam', | ||
posts: [ 1 ] | ||
}); | ||
}, /You're trying to create a user model and you passed in "1" under the posts key, but that key is a HasMany relationship./); | ||
}); | ||
|
||
test('it errors when passing in the wrong type for a HasMany association foreign key', function(assert) { | ||
assert.throws(() => { | ||
this.server.schema.users.create({ | ||
name: 'Sam', | ||
postIds: 'foo' | ||
}); | ||
}, /You're trying to create a user model and you passed in "foo" under the postIds key, but that key is a foreign key for a HasMany relationship./); | ||
}); | ||
|
||
test('it errors when passing in a missing foreign key for a HasMany association foreign key', function(assert) { | ||
assert.throws(() => { | ||
this.server.schema.users.create({ | ||
name: 'Sam', | ||
postIds: [ 2 ] | ||
}); | ||
}, /You're instantiating a user that has a postIds of 2, but some of those records don't exist in the database/); | ||
}); | ||
|
||
test('it errors when passing in the wrong type for a BelongsTo association', function(assert) { | ||
assert.throws(() => { | ||
this.server.schema.posts.create({ | ||
title: 'Post 1', | ||
author: 'sam' | ||
}); | ||
}, /You're trying to create a post model and you passed in "sam" under the author key, but that key is a BelongsTo relationship./); | ||
}); | ||
|
||
test('it errors when passing in a missing foreign key for a BelongsTo association foreign key', function(assert) { | ||
assert.throws(() => { | ||
this.server.schema.posts.create({ | ||
title: 'Post 1', | ||
authorId: 1 | ||
}); | ||
}, /You're instantiating a post that has a authorId of 1, but that record doesn't exist in the database/); | ||
}); | ||
|
||
}); |