Created
September 10, 2013 14:21
-
-
Save ehelms/6510100 to your computer and use it in GitHub Desktop.
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
angular.module('Bastion.test-mocks').factory('Repository', function() { | |
var Repository, mockRepository; | |
mockRepository = { | |
id: 1, | |
failed: false, | |
$update: function(success, error) { | |
if (self.failed) { | |
error({ data: {errors: {}}}); | |
} else { | |
success(self); | |
} | |
}, | |
$delete: function(callback) { | |
callback(); | |
} | |
} | |
Repository = { | |
mockRepositories: { | |
results: [ | |
mockRepository | |
], | |
total: 2, | |
subtotal: 1 | |
}, | |
get: function(id) { | |
return Repository.mockRepositories[id]; | |
}, | |
query: function(params, callback) { | |
callback(Repository.mockRepositories); | |
return Repository.mockRepositories; | |
} | |
}; | |
return Repository; | |
}); | |
angular.module('Bastion.test-mocks').factory('MockResource', function() { | |
var Resource, mockResource, errorResponse; | |
errorResponse = { | |
data: { | |
errors: { | |
name: 'Invalid name' | |
} | |
} | |
}; | |
mockResource = { | |
id: 1, | |
name: 'Test Resource', | |
failed: false, | |
$save: function(success, error) { | |
if (!mockResource.failed) { | |
success(); | |
} else { | |
error(errorResponse); | |
} | |
}, | |
$update: function(success, error) { | |
if (mockResource.failed) { | |
error({ data: {errors: {}}}); | |
} else { | |
success(mockResource); | |
} | |
}, | |
$delete: function(callback) { | |
callback(); | |
} | |
} | |
Resource = function() { | |
return mockResource; | |
}; | |
Resource.mockResources = { | |
results: [ | |
mockResource | |
], | |
total: 2, | |
subtotal: 1 | |
}; | |
Resource.get = function(id) { | |
return Resource.mockResources[id]; | |
}; | |
Resource.query = function(params, callback) { | |
callback(Resource.mockResource); | |
return Resource.mockResource | |
} | |
return Resource; | |
}); | |
angular.module('Bastion.test-mocks').factory('MockForm', function() { | |
return { | |
name: { | |
$invalid: false, | |
$setValidity: function() { | |
this.$invalid = true; | |
}, | |
$error: { | |
messages: [] | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment