github.com/kjdelisle/consul@v1.4.5/ui-v2/tests/integration/adapters/token/url-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupTest } from 'ember-qunit';
     3  import makeAttrable from 'consul-ui/utils/makeAttrable';
     4  module('Integration | Adapter | token | url', function(hooks) {
     5    setupTest(hooks);
     6    const dc = 'dc-1';
     7    const id = 'policy-id';
     8    test('urlForQuery returns the correct url', function(assert) {
     9      const adapter = this.owner.lookup('adapter:token');
    10      const expected = `/v1/acl/tokens?dc=${dc}`;
    11      const actual = adapter.urlForQuery({
    12        dc: dc,
    13      });
    14      assert.equal(actual, expected);
    15    });
    16    test('urlForQueryRecord returns the correct url', function(assert) {
    17      const adapter = this.owner.lookup('adapter:token');
    18      const expected = `/v1/acl/token/${id}?dc=${dc}`;
    19      const actual = adapter.urlForQueryRecord({
    20        dc: dc,
    21        id: id,
    22      });
    23      assert.equal(actual, expected);
    24    });
    25    test("urlForQueryRecord throws if you don't specify an id", function(assert) {
    26      const adapter = this.owner.lookup('adapter:token');
    27      assert.throws(function() {
    28        adapter.urlForQueryRecord({
    29          dc: dc,
    30        });
    31      });
    32    });
    33    test('urlForCreateRecord returns the correct url', function(assert) {
    34      const adapter = this.owner.lookup('adapter:token');
    35      const expected = `/v1/acl/token?dc=${dc}`;
    36      const actual = adapter.urlForCreateRecord(
    37        'token',
    38        makeAttrable({
    39          Datacenter: dc,
    40        })
    41      );
    42      assert.equal(actual, expected);
    43    });
    44    test('urlForUpdateRecord returns the correct url (without Rules it uses the v2 API)', function(assert) {
    45      const adapter = this.owner.lookup('adapter:token');
    46      const expected = `/v1/acl/token/${id}?dc=${dc}`;
    47      const actual = adapter.urlForUpdateRecord(
    48        id,
    49        'token',
    50        makeAttrable({
    51          Datacenter: dc,
    52          AccessorID: id,
    53        })
    54      );
    55      assert.equal(actual, expected);
    56    });
    57    test('urlForUpdateRecord returns the correct url (with Rules it uses the v1 API)', function(assert) {
    58      const adapter = this.owner.lookup('adapter:token');
    59      const expected = `/v1/acl/update?dc=${dc}`;
    60      const actual = adapter.urlForUpdateRecord(
    61        id,
    62        'token',
    63        makeAttrable({
    64          Rules: 'key {}',
    65          Datacenter: dc,
    66          AccessorID: id,
    67        })
    68      );
    69      assert.equal(actual, expected);
    70    });
    71    test('urlForDeleteRecord returns the correct url', function(assert) {
    72      const adapter = this.owner.lookup('adapter:token');
    73      const expected = `/v1/acl/token/${id}?dc=${dc}`;
    74      const actual = adapter.urlForDeleteRecord(
    75        id,
    76        'token',
    77        makeAttrable({
    78          Datacenter: dc,
    79          AccessorID: id,
    80        })
    81      );
    82      assert.equal(actual, expected);
    83    });
    84  });