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

     1  import { moduleFor, test } from 'ember-qunit';
     2  import { skip } from 'qunit';
     3  import repo from 'consul-ui/tests/helpers/repo';
     4  const NAME = 'service';
     5  moduleFor(`service:repository/${NAME}`, `Integration | Service | ${NAME}`, {
     6    // Specify the other units that are required for this test.
     7    integration: true,
     8  });
     9  const dc = 'dc-1';
    10  const id = 'token-name';
    11  test('findByDatacenter returns the correct data for list endpoint', function(assert) {
    12    return repo(
    13      'Service',
    14      'findAllByDatacenter',
    15      this.subject(),
    16      function retrieveStub(stub) {
    17        return stub(`/v1/internal/ui/services?dc=${dc}`, {
    18          CONSUL_SERVICE_COUNT: '100',
    19        });
    20      },
    21      function performTest(service) {
    22        return service.findAllByDatacenter(dc);
    23      },
    24      function performAssertion(actual, expected) {
    25        assert.deepEqual(
    26          actual,
    27          expected(function(payload) {
    28            return payload.map(item =>
    29              Object.assign({}, item, {
    30                Datacenter: dc,
    31                uid: `["${dc}","${item.Name}"]`,
    32              })
    33            );
    34          })
    35        );
    36      }
    37    );
    38  });
    39  skip('findBySlug returns a sane tree');
    40  test('findBySlug returns the correct data for item endpoint', function(assert) {
    41    return repo(
    42      'Service',
    43      'findBySlug',
    44      this.subject(),
    45      function(stub) {
    46        return stub(`/v1/health/service/${id}?dc=${dc}`, {
    47          CONSUL_NODE_COUNT: 1,
    48        });
    49      },
    50      function(service) {
    51        return service.findBySlug(id, dc);
    52      },
    53      function(actual, expected) {
    54        assert.deepEqual(
    55          actual,
    56          expected(function(payload) {
    57            // TODO: So this tree is all 'wrong', it's not having any major impact
    58            // this this tree needs revisting to something that makes more sense
    59            payload = Object.assign(
    60              {},
    61              { Nodes: payload },
    62              {
    63                Datacenter: dc,
    64                uid: `["${dc}","${id}"]`,
    65              }
    66            );
    67            const nodes = payload.Nodes;
    68            const service = payload.Nodes[0];
    69            service.Nodes = nodes;
    70            service.Tags = payload.Nodes[0].Service.Tags;
    71  
    72            return service;
    73          })
    74        );
    75      }
    76    );
    77  });