-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote out unit testing and also added expanded component/project-user…
… to include error message when projectJoin fails added flashOptions object to clear up code
- Loading branch information
Showing
2 changed files
with
90 additions
and
8 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 |
---|---|---|
@@ -1,15 +1,91 @@ | ||
import RSVP from 'rsvp'; | ||
import { set } from '@ember/object'; | ||
import { moduleFor, test } from 'ember-qunit'; | ||
|
||
moduleFor('service:project-user', 'Unit | Service | project user', { | ||
// Specify the other units that are required for this test. | ||
needs: [ | ||
'service:current-user', | ||
'service:flash-messages' | ||
'service:flash-messages', | ||
'service:session', | ||
'service:metrics' | ||
] | ||
}); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
test('it creates a new projectUser with properties', function(assert) { | ||
assert.expect(3); | ||
let done = assert.async(); | ||
let service = this.subject(); | ||
assert.ok(service); | ||
let user = { id: 1 }; | ||
let project = { title: 'Code Corps' }; | ||
let projectUser = { project, user, role: 'pending' }; | ||
|
||
let mockCurrentUser = { user }; | ||
|
||
let mockStore = { | ||
createRecord(modelName, inputProperties) { | ||
return { | ||
save() { | ||
assert.equal(modelName, 'project-user'); | ||
assert.deepEqual(inputProperties, projectUser); | ||
return RSVP.resolve(projectUser); | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
// test doesn't care what the message is, just that it was called | ||
// need to support function chaining because actual flash-messages | ||
// service does function chaining and our component calls to clear all messages first | ||
// so the fake needs to support that. | ||
|
||
let mockFlashMessage = { | ||
success() { | ||
assert.ok(true); | ||
return this; | ||
}, | ||
clearMessages() { | ||
return this; | ||
} | ||
}; | ||
|
||
set(service, 'currentUser', mockCurrentUser); | ||
set(service, 'flashMessages', mockFlashMessage); | ||
set(service, 'store', mockStore); | ||
|
||
service.joinProject(project).then(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
test('it sends an error flash message if joinProject fails', function(assert) { | ||
assert.expect(1); | ||
let service = this.subject(); | ||
let done = assert.async(); | ||
|
||
let mockStore = { | ||
createRecord() { | ||
return { | ||
save() { | ||
return RSVP.reject(); | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
let mockFlashMessage = { | ||
danger() { | ||
assert.ok(true); | ||
return this; | ||
}, | ||
clearMessages() { | ||
return this; | ||
} | ||
}; | ||
|
||
set(service, 'flashMessages', mockFlashMessage); | ||
set(service, 'store', mockStore); | ||
|
||
service.joinProject().then(() => { | ||
done(); | ||
}); | ||
}); |