github.com/hernad/nomad@v1.6.112/ui/tests/unit/serializers/job-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { module, test } from 'qunit';
     7  import { setupTest } from 'ember-qunit';
     8  import JobModel from 'nomad-ui/models/job';
     9  
    10  module('Unit | Serializer | Job', function (hooks) {
    11    setupTest(hooks);
    12    hooks.beforeEach(function () {
    13      this.store = this.owner.lookup('service:store');
    14      this.subject = () => this.store.serializerFor('job');
    15    });
    16  
    17    test('`default` is used as the namespace in the job ID when there is no namespace in the payload', async function (assert) {
    18      const original = {
    19        ID: 'example',
    20        Name: 'example',
    21      };
    22  
    23      const { data } = this.subject().normalize(JobModel, original);
    24      assert.equal(data.id, JSON.stringify([data.attributes.name, 'default']));
    25    });
    26  
    27    test('The ID of the record is a composite of both the name and the namespace', async function (assert) {
    28      const original = {
    29        ID: 'example',
    30        Name: 'example',
    31        Namespace: 'special-namespace',
    32      };
    33  
    34      const { data } = this.subject().normalize(JobModel, original);
    35      assert.equal(
    36        data.id,
    37        JSON.stringify([
    38          data.attributes.name,
    39          data.relationships.namespace.data.id,
    40        ])
    41      );
    42    });
    43  });