|
@@ -5,11 +5,11 @@ import startApp from '../helpers/start-app';
|
|
|
|
|
|
var application, container, service;
|
|
|
|
|
|
-module('Acceptance: RPC Service', {
|
|
|
+module('Acceptance: Ajax Service', {
|
|
|
beforeEach: function() {
|
|
|
application = startApp();
|
|
|
container = application.__container__;
|
|
|
- service = container.lookup('service:rpc');
|
|
|
+ service = container.lookup('service:ajax');
|
|
|
},
|
|
|
|
|
|
afterEach: function() {
|
|
@@ -49,7 +49,131 @@ test('buildProcedureURL builds valid url', function(assert) {
|
|
|
assert.equal(url, '/api/thread/1/close/');
|
|
|
});
|
|
|
|
|
|
-test('successful RPC', function(assert) {
|
|
|
+test('successful get', function(assert) {
|
|
|
+ assert.expect(2);
|
|
|
+ var done = assert.async();
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/some-value/',
|
|
|
+ status: 200,
|
|
|
+ responseText: {
|
|
|
+ 'detail': 'it works'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ service.get('some-value').then(function(data) {
|
|
|
+ assert.equal(data.detail, 'it works');
|
|
|
+ }, function() {
|
|
|
+ assert.ok(false, 'get call should pass');
|
|
|
+ }).finally(function() {
|
|
|
+ assert.ok(true, 'finally() was called');
|
|
|
+ done();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+test('failed post', function(assert) {
|
|
|
+ assert.expect(2);
|
|
|
+ var done = assert.async();
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/some-value/',
|
|
|
+ status: 400,
|
|
|
+ responseText: {
|
|
|
+ 'detail': 'it fails'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ service.get('some-value').then(function(data) {
|
|
|
+ assert.ok(false, 'get call should fail');
|
|
|
+ }, function(jqXHR) {
|
|
|
+ var rejection = jqXHR.responseJSON;
|
|
|
+ assert.equal(rejection.detail, 'it fails');
|
|
|
+ }).finally(function() {
|
|
|
+ assert.ok(true, 'finally() was called');
|
|
|
+ done();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+test('successful model prop get', function(assert) {
|
|
|
+ assert.expect(2);
|
|
|
+ var done = assert.async();
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/legal-pages/privacy-policy/',
|
|
|
+ status: 200,
|
|
|
+ responseText: {
|
|
|
+ 'id': 'privacy-policy',
|
|
|
+ 'title': '',
|
|
|
+ 'link': '',
|
|
|
+ 'body': ''
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/legal-pages/privacy-policy/some-rpc/',
|
|
|
+ status: 200,
|
|
|
+ responseText: {
|
|
|
+ 'detail': 'it works'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Ember.run(function() {
|
|
|
+ var store = container.lookup('store:main');
|
|
|
+
|
|
|
+ store.find('legal-page', 'privacy-policy').then(function(record) {
|
|
|
+ service.get(record, 'some-rpc').then(function(data) {
|
|
|
+ assert.equal(data.detail, 'it works');
|
|
|
+ }, function() {
|
|
|
+ assert.ok(false, 'model get call should pass');
|
|
|
+ }).finally(function() {
|
|
|
+ assert.ok(true, 'finally() was called');
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+test('failed model prop get', function(assert) {
|
|
|
+ assert.expect(2);
|
|
|
+ var done = assert.async();
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/legal-pages/privacy-policy/',
|
|
|
+ status: 200,
|
|
|
+ responseText: {
|
|
|
+ 'id': 'privacy-policy',
|
|
|
+ 'title': '',
|
|
|
+ 'link': '',
|
|
|
+ 'body': ''
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Ember.$.mockjax({
|
|
|
+ url: '/api/legal-pages/privacy-policy/some-rpc/',
|
|
|
+ status: 400,
|
|
|
+ responseText: {
|
|
|
+ 'detail': 'it failed'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Ember.run(function() {
|
|
|
+ var store = container.lookup('store:main');
|
|
|
+
|
|
|
+ store.find('legal-page', 'privacy-policy').then(function(record) {
|
|
|
+ service.get(record, 'some-rpc').then(function() {
|
|
|
+ assert.ok(false, 'get call should fail');
|
|
|
+ }, function(jqXHR) {
|
|
|
+ var rejection = jqXHR.responseJSON;
|
|
|
+ assert.equal(rejection.detail, 'it failed');
|
|
|
+ }).finally(function() {
|
|
|
+ assert.ok(true, 'finally() was called');
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+test('successful post', function(assert) {
|
|
|
assert.expect(2);
|
|
|
var done = assert.async();
|
|
|
|
|
@@ -61,7 +185,7 @@ test('successful RPC', function(assert) {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- service.ajax('some-rpc').then(function(data) {
|
|
|
+ service.post('some-rpc').then(function(data) {
|
|
|
assert.equal(data.detail, 'it works');
|
|
|
}, function() {
|
|
|
assert.ok(false, 'rpc call should pass');
|
|
@@ -71,7 +195,7 @@ test('successful RPC', function(assert) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-test('failed RPC', function(assert) {
|
|
|
+test('failed post', function(assert) {
|
|
|
assert.expect(2);
|
|
|
var done = assert.async();
|
|
|
|
|
@@ -83,7 +207,7 @@ test('failed RPC', function(assert) {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- service.ajax('some-rpc').then(function() {
|
|
|
+ service.post('some-rpc').then(function() {
|
|
|
assert.ok(false, 'rpc call should fail');
|
|
|
}, function(jqXHR) {
|
|
|
var rejection = jqXHR.responseJSON;
|
|
@@ -94,7 +218,7 @@ test('failed RPC', function(assert) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-test('successful model RPC', function(assert) {
|
|
|
+test('successful model rpc post', function(assert) {
|
|
|
assert.expect(2);
|
|
|
var done = assert.async();
|
|
|
|
|
@@ -121,7 +245,7 @@ test('successful model RPC', function(assert) {
|
|
|
var store = container.lookup('store:main');
|
|
|
|
|
|
store.find('legal-page', 'privacy-policy').then(function(record) {
|
|
|
- service.ajax(record, 'some-rpc').then(function(data) {
|
|
|
+ service.post(record, 'some-rpc').then(function(data) {
|
|
|
assert.equal(data.detail, 'it works');
|
|
|
}, function() {
|
|
|
assert.ok(false, 'rpc call should pass');
|
|
@@ -133,7 +257,7 @@ test('successful model RPC', function(assert) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-test('failed model RPC', function(assert) {
|
|
|
+test('failed model rpc post', function(assert) {
|
|
|
assert.expect(2);
|
|
|
var done = assert.async();
|
|
|
|
|
@@ -160,7 +284,7 @@ test('failed model RPC', function(assert) {
|
|
|
var store = container.lookup('store:main');
|
|
|
|
|
|
store.find('legal-page', 'privacy-policy').then(function(record) {
|
|
|
- service.ajax(record, 'some-rpc').then(function() {
|
|
|
+ service.post(record, 'some-rpc').then(function() {
|
|
|
assert.ok(false, 'rpc call should fail');
|
|
|
}, function(jqXHR) {
|
|
|
var rejection = jqXHR.responseJSON;
|