-/* ------------ Fixtures/constants ------------ */
-
-var VALID_CONTACT_ID = 3;
-var MALFORMED_CONTACT_ID = 'z';
-
-var ContactModel = Backbone.Model.extend({});
-CRM.Backbone.extendModel(ContactModel, 'Contact');
-CRM.Backbone.trackSaved(ContactModel);
-
-var ContactCollection = Backbone.Collection.extend({
- model: ContactModel
-});
-CRM.Backbone.extendCollection(ContactCollection);
-
-/* ------------ Assertions ------------ */
-
-/**
- * Assert "result" contains an API error
- * @param result
- */
-function assertApiError(result) {
- equal(1, result.is_error, 'Expected error boolean');
- ok(result.error_message.length > 0, 'Expected error message')
-}
-
-/**
- * When calling an AJAX operation which should return successfully,
- * make sure that there's no error by setting a callback (error: onUnexpectedError)
- */
-function onUnexpectedError(ignore, result) {
- if (result && result.error_message) {
- ok(false, "API returned an unexpected error: " + result.error_message);
- } else {
- ok(false, "API returned an unexpected error: (missing message)");
- }
- start();
-}
-
-/**
- * When calling an AJAX operation which should return an error,
- * make sure that there's no success by setting a callback (success: onUnexpectedSuccess)
- */
-function onUnexpectedSuccess(ignore) {
- ok(false, "API succeeded - but failure was expected");
- start();
-}
-
-/* ------------ Test cases ------------ */
-
-module('model - read');
-
-asyncTest("fetch (ok)", function() {
- var c = new ContactModel({id: VALID_CONTACT_ID});
- c.fetch({
- error: onUnexpectedError,
- success: function() {
- notEqual(-1, _.indexOf(['Individual', 'Household', 'Organization'], c.get('contact_type')), 'Loaded contact with valid contact_type');
- ok(c.get('display_name') != '', 'Loaded contact with valid name');
- start();
- }
- });
-});
-
-asyncTest("fetch (error)", function() {
- var c = new ContactModel({id: MALFORMED_CONTACT_ID});
- c.fetch({
- success: onUnexpectedSuccess,
- error: function(model, error) {
- assertApiError(error);
- start();
- }
- });
-});