Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished integration tests for async methods. #15
- Loading branch information
Showing
12 changed files
with
105 additions
and
33 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
File renamed without changes.
File renamed without changes.
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
62 changes: 62 additions & 0 deletions
62
test/integration/datastore/async_methods/refresh/index.test.js
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,62 @@ | ||
describe('DS.refresh(resourceName, id[, options]): ', function () { | ||
var errorPrefix = 'DS.refresh(resourceName, id[, options]): '; | ||
|
||
it('should throw an error when method pre-conditions are not met', function (done) { | ||
assert.throws(function () { | ||
DS.refresh('does not exist', 5); | ||
}, DS.errors.RuntimeError, errorPrefix + 'does not exist is not a registered resource!'); | ||
|
||
angular.forEach(TYPES_EXCEPT_STRING_OR_NUMBER, function (key) { | ||
assert.throws(function () { | ||
DS.refresh('post', key); | ||
}, DS.errors.IllegalArgumentError, errorPrefix + 'id: Must be a string or a number!'); | ||
}); | ||
|
||
angular.forEach(TYPES_EXCEPT_OBJECT, function (key) { | ||
if (key) { | ||
assert.throws(function () { | ||
DS.refresh('post', 5, key); | ||
}, DS.errors.IllegalArgumentError, errorPrefix + 'options: Must be an object!'); | ||
} | ||
}); | ||
|
||
done(); | ||
}); | ||
it('should get an item from the server', function (done) { | ||
|
||
// Should do nothing because the data isn't in the store | ||
assert.isFalse(DS.refresh('post', 5)); | ||
|
||
assert.isUndefined(DS.get('post', 5), 'The post should not be in the store yet'); | ||
|
||
DS.inject('post', p1); | ||
assert.deepEqual(DS.get('post', 5), p1, 'The post is now in the store'); | ||
|
||
var initialLastModified = DS.lastModified('post', 5); | ||
|
||
$httpBackend.expectGET('http://test.angular-cache.com/posts/5').respond(200, { author: 'John', age: 31, id: 5 }); | ||
|
||
// Should refresh the item that's in the store | ||
DS.refresh('post', 5).then(function (post) { | ||
assert.deepEqual(post, { author: 'John', age: 31, id: 5 }); | ||
}, function (err) { | ||
console.error(err.stack); | ||
fail('Should not have rejected!'); | ||
}); | ||
|
||
// Should have no effect because the request is already pending | ||
DS.refresh('post', 5).then(function (post) { | ||
assert.deepEqual(post, { author: 'John', age: 31, id: 5 }); | ||
}, function (err) { | ||
console.error(err.stack); | ||
fail('Should not have rejected!'); | ||
}); | ||
|
||
$httpBackend.flush(); | ||
|
||
assert.deepEqual(DS.get('post', 5), { author: 'John', age: 31, id: 5 }, 'The post has been refreshed'); | ||
assert.notEqual(DS.lastModified('post', 5), initialLastModified); | ||
|
||
done(); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.