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

     1  import { moduleFor, test } from 'ember-qunit';
     2  import repo from 'consul-ui/tests/helpers/repo';
     3  const NAME = 'intention';
     4  moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
     5    // Specify the other units that are required for this test.
     6    needs: [
     7      'service:settings',
     8      'service:store',
     9      `adapter:${NAME}`,
    10      `serializer:${NAME}`,
    11      `model:${NAME}`,
    12    ],
    13  });
    14  
    15  const dc = 'dc-1';
    16  const id = 'token-name';
    17  test('findAllByDatacenter returns the correct data for list endpoint', function(assert) {
    18    return repo(
    19      'Intention',
    20      'findAllByDatacenter',
    21      this.subject(),
    22      function retrieveStub(stub) {
    23        return stub(`/v1/connect/intentions?dc=${dc}`, {
    24          CONSUL_INTENTION_COUNT: '100',
    25        });
    26      },
    27      function performTest(service) {
    28        return service.findAllByDatacenter(dc);
    29      },
    30      function performAssertion(actual, expected) {
    31        assert.deepEqual(
    32          actual,
    33          expected(function(payload) {
    34            return payload.map(item =>
    35              Object.assign({}, item, {
    36                CreatedAt: new Date(item.CreatedAt),
    37                UpdatedAt: new Date(item.UpdatedAt),
    38                Datacenter: dc,
    39                uid: `["${dc}","${item.ID}"]`,
    40              })
    41            );
    42          })
    43        );
    44      }
    45    );
    46  });
    47  test('findBySlug returns the correct data for item endpoint', function(assert) {
    48    return repo(
    49      'Intention',
    50      'findBySlug',
    51      this.subject(),
    52      function(stub) {
    53        return stub(`/v1/connect/intentions/${id}?dc=${dc}`);
    54      },
    55      function(service) {
    56        return service.findBySlug(id, dc);
    57      },
    58      function(actual, expected) {
    59        assert.deepEqual(
    60          actual,
    61          expected(function(payload) {
    62            const item = payload;
    63            return Object.assign({}, item, {
    64              CreatedAt: new Date(item.CreatedAt),
    65              UpdatedAt: new Date(item.UpdatedAt),
    66              Datacenter: dc,
    67              uid: `["${dc}","${item.ID}"]`,
    68            });
    69          })
    70        );
    71      }
    72    );
    73  });