Skip to content

Commit

Permalink
update task model tests & add relationship test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
WenInCode committed Oct 2, 2016
1 parent 59ba1ff commit b44d038
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/helpers/relationship.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from 'ember-qunit';
import Ember from 'ember';

// source: https://gist.github.com/he9qi/b6354a81a0672dc63294
export function testForHasMany(name, many) {
test('should have many ' + many, function(assert) {
assert.expect(2);
const Model = this.store().modelFor(name);
const relationship = Ember.get(Model, 'relationshipsByName').get(many);

assert.equal(relationship.key, many, 'has relationship with ' + many);
assert.equal(relationship.kind, 'hasMany', 'kind of relationship is hasMany');
});
}

export function testForBelongsTo(name, belongsTo) {
test('should belong to ' + belongsTo, function(assert) {
assert.expect(2);
const Model = this.store().modelFor(name);
const relationship = Ember.get(Model, 'relationshipsByName').get(belongsTo);

assert.equal(relationship.key, belongsTo, 'has relationship with ' + belongsTo);
assert.equal(relationship.kind, 'belongsTo', 'kind of relationship is belongsTo');
});
}
23 changes: 23 additions & 0 deletions tests/unit/models/task-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { moduleForModel, test } from 'ember-qunit';
import { testForBelongsTo, testForHasMany } from '../../helpers/relationship';

moduleForModel('task', 'Unit | Model | task', {
// Specify the other units that are required for this test.
Expand All @@ -17,6 +18,28 @@ test('it exists', function(assert) {
assert.ok(!!model);
});

test('it should have all of its attributes', function(assert) {
assert.expect(8);

let task = this.subject();
let attributes = Object.keys(task.toJSON());

assert.ok(attributes.includes('body'), 'task should have the body attribute');
assert.ok(attributes.includes('insertedAt'), 'task should have the insertedAt attribute');
assert.ok(attributes.includes('likesCount'), 'task should have the likesCount attribute');
assert.ok(attributes.includes('markdown'), 'task should have the markdown attribute');
assert.ok(attributes.includes('number'), 'task should have the number attribute');
assert.ok(attributes.includes('status'), 'task should have the status attribute');
assert.ok(attributes.includes('taskType'), 'task should have the taskType attribute');
assert.ok(attributes.includes('title'), 'task should have the title attribute');
});

testForBelongsTo('task', 'project');
testForBelongsTo('task', 'user');
testForHasMany('task', 'comments');
testForHasMany('task', 'commentUserMentions');
testForHasMany('task', 'taskUserMentions');

test('it correctly identifies code in the body', function(assert) {
assert.expect(1);

Expand Down

0 comments on commit b44d038

Please sign in to comment.