From b44d03858067f3181efb5f164aa709a54175eb36 Mon Sep 17 00:00:00 2001 From: wenincode Date: Sat, 1 Oct 2016 23:10:02 -0600 Subject: [PATCH] update task model tests & add relationship test helpers --- tests/helpers/relationship.js | 25 +++++++++++++++++++++++++ tests/unit/models/task-test.js | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/helpers/relationship.js diff --git a/tests/helpers/relationship.js b/tests/helpers/relationship.js new file mode 100644 index 000000000..133bf7eff --- /dev/null +++ b/tests/helpers/relationship.js @@ -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'); + }); +} diff --git a/tests/unit/models/task-test.js b/tests/unit/models/task-test.js index bb80613b7..fcb5d4034 100644 --- a/tests/unit/models/task-test.js +++ b/tests/unit/models/task-test.js @@ -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. @@ -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);