github.com/outbrain/consul@v1.4.5/ui-v2/tests/integration/services/repository/kv-test.js (about)

     1  import { moduleFor, test } from 'ember-qunit';
     2  import repo from 'consul-ui/tests/helpers/repo';
     3  const NAME = 'kv';
     4  moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
     5    // Specify the other units that are required for this test.
     6    integration: true,
     7  });
     8  const dc = 'dc-1';
     9  const id = 'key-name';
    10  test('findAllBySlug returns the correct data for list endpoint', function(assert) {
    11    return repo(
    12      'Kv',
    13      'findAllBySlug',
    14      this.subject(),
    15      function retrieveTest(stub) {
    16        return stub(`/v1/kv/${id}?keys&dc=${dc}`, {
    17          CONSUL_KV_COUNT: '1',
    18        });
    19      },
    20      function performTest(service) {
    21        return service.findAllBySlug(id, dc);
    22      },
    23      function performAssertion(actual, expected) {
    24        assert.deepEqual(
    25          actual,
    26          expected(function(payload) {
    27            return payload.map(item => {
    28              return {
    29                Datacenter: dc,
    30                uid: `["${dc}","${item}"]`,
    31                Key: item,
    32              };
    33            });
    34          })
    35        );
    36      }
    37    );
    38  });
    39  test('findAllBySlug returns the correct data for item endpoint', function(assert) {
    40    return repo(
    41      'Kv',
    42      'findAllBySlug',
    43      this.subject(),
    44      function(stub) {
    45        return stub(`/v1/kv/${id}?dc=${dc}`);
    46      },
    47      function(service) {
    48        return service.findBySlug(id, dc);
    49      },
    50      function(actual, expected) {
    51        assert.deepEqual(
    52          actual,
    53          expected(function(payload) {
    54            const item = payload[0];
    55            return Object.assign({}, item, {
    56              Datacenter: dc,
    57              uid: `["${dc}","${item.Key}"]`,
    58            });
    59          })
    60        );
    61      }
    62    );
    63  });