yarn-node-app-test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import { moduleFor, test } from 'ember-qunit';
  19. moduleFor('adapter:yarn-node-app', 'Unit | Adapter | NodeApp', {
  20. });
  21. test('Basic creation', function(assert) {
  22. let adapter = this.subject();
  23. assert.expect(11);
  24. assert.ok(adapter);
  25. assert.ok(adapter.urlForQueryRecord);
  26. assert.ok(adapter.queryRecord);
  27. assert.ok(adapter.urlForQuery);
  28. assert.ok(adapter.query);
  29. assert.ok(adapter.ajax);
  30. assert.ok(adapter.headers);
  31. assert.ok(adapter.host);
  32. assert.ok(adapter.namespace);
  33. assert.equal("application/json", adapter.headers.Accept);
  34. assert.equal("ws/v1/node", adapter.namespace);
  35. });
  36. test('urlForQueryRecord test', function(assert) {
  37. let adapter = this.subject();
  38. let host = adapter.host;
  39. assert.equal(
  40. host + "localhost:8042/ws/v1/node/apps/application_1111111111_1111",
  41. adapter.urlForQueryRecord(
  42. {nodeAddr: "localhost:8042", appId: "application_1111111111_1111"}));
  43. });
  44. test('urlForQuery test', function(assert) {
  45. let adapter = this.subject();
  46. let host = adapter.host;
  47. assert.equal(host + "localhost:8042/ws/v1/node/apps",
  48. adapter.urlForQuery({nodeAddr: "localhost:8042"}));
  49. });
  50. test('query test', function(assert) {
  51. let adapter = this.subject(),
  52. testModel = { modelName: "testModel" },
  53. testStore = {},
  54. testQuery = {nodeAddr: "localhost:8042"};
  55. let host = adapter.host;
  56. assert.expect(3);
  57. adapter.ajax = function (url, method, hash) {
  58. assert.equal(host + "localhost:8042/ws/v1/node/apps", url);
  59. assert.equal('GET', method);
  60. assert.equal(null, hash.data);
  61. };
  62. adapter.query(testStore, testModel, testQuery);
  63. });
  64. test('queryRecord test', function(assert) {
  65. let adapter = this.subject(),
  66. testModel = { modelName: "testModel" },
  67. testStore = {},
  68. testQuery = {
  69. nodeAddr: "localhost:8042",
  70. appId: "application_1111111111_1111"
  71. };
  72. let host = adapter.host;
  73. assert.expect(3);
  74. adapter.ajax = function (url, method, hash) {
  75. assert.equal(
  76. host + "localhost:8042/ws/v1/node/apps/application_1111111111_1111",
  77. url);
  78. assert.equal('GET', method);
  79. assert.equal(null, hash.data);
  80. };
  81. adapter.queryRecord(testStore, testModel, testQuery);
  82. });