<commit_before>import { moduleFor, test } from 'ember-qunit';

import Ember from 'ember';

let testSerializedData = {
  'test.txt': {
    content_type: 'text/plain',
    data: 'hello world!'
  },
  'stub.json': {
    stub: true,
    content_type: 'application/json'
  }
};

let testDeserializedData = [
  Ember.Object.create({
    name: 'test.txt',
    content_type: 'text/plain',
    data: 'hello world!'
  }),
  Ember.Object.create({
    name: 'stub.json',
    content_type: 'application/json',
    stub: true
  })
];

moduleFor('transform:attachment', 'Unit | Transform | attachment', {});

test('it serializes an attachment', function(assert) {
  let transform = this.subject();
  assert.equal(transform.serialize(null), null);
  assert.equal(transform.serialize(undefined), null);

  let serializedData = transform.serialize(testDeserializedData);
  let name = testDeserializedData[0].get('name');

  assert.equal(serializedData[name].content_type, testSerializedData[name].content_type);
  assert.equal(serializedData[name].data, testSerializedData[name].data);

  let stub = testDeserializedData[1].get('name');

  assert.equal(serializedData[stub].content_type, testSerializedData[stub].content_type);
  assert.equal(serializedData[stub].stub, true);
});

test('it deserializes an attachment', function(assert) {
  let transform = this.subject();
  assert.equal(transform.deserialize(null), null);
  assert.equal(transform.deserialize(undefined), null);

  let deserializedData = transform.deserialize(testSerializedData);

  assert.equal(deserializedData[0].get('name'), testDeserializedData[0].get('name'));
  assert.equal(deserializedData[0].get('content_type'), testDeserializedData[0].get('content_type'));
  assert.equal(deserializedData[0].get('data'), testDeserializedData[0].get('data'));

  assert.equal(deserializedData[1].get('name'), testDeserializedData[1].get('name'));
  assert.equal(deserializedData[1].get('content_type'), testDeserializedData[1].get('content_type'));
  assert.equal(deserializedData[1].get('stub'), true);
});<commit_msg>Test that `digest` and `length` properties of a stub attachment are preserved<commit_after>import { moduleFor, test } from 'ember-qunit';

import Ember from 'ember';

let testSerializedData = {
  'hello.txt': {
    content_type: 'text/plain',
    data: 'aGVsbG8gd29ybGQ=',
    digest: "md5-7mkg+nM0HN26sZkLN8KVSA=="
    // CouchDB doesn't add 'length'
  },
  'stub.txt': {
    stub: true,
    content_type: 'text/plain',
    digest: "md5-7mkg+nM0HN26sZkLN8KVSA==",
    length: 11
  },
};

let testDeserializedData = [
  Ember.Object.create({
    name: 'hello.txt',
    content_type: 'text/plain',
    data: 'aGVsbG8gd29ybGQ=',
  }),
  Ember.Object.create({
    name: 'stub.txt',
    content_type: 'text/plain',
    stub: true,
    digest: 'md5-7mkg+nM0HN26sZkLN8KVSA==',
    length: 11
  })
];

moduleFor('transform:attachment', 'Unit | Transform | attachment', {});

test('it serializes an attachment', function(assert) {
  let transform = this.subject();
  assert.equal(transform.serialize(null), null);
  assert.equal(transform.serialize(undefined), null);

  let serializedData = transform.serialize(testDeserializedData);

  let hello = testDeserializedData[0].get('name');
  assert.equal(hello, 'hello.txt');
  assert.equal(serializedData[hello].content_type, testSerializedData[hello].content_type);
  assert.equal(serializedData[hello].data, testSerializedData[hello].data);

  let stub = testDeserializedData[1].get('name');
  assert.equal(stub, 'stub.txt');
  assert.equal(serializedData[stub].content_type, testSerializedData[stub].content_type);
  assert.equal(serializedData[stub].stub, true);
});

test('it deserializes an attachment', function(assert) {
  let transform = this.subject();
  assert.equal(transform.deserialize(null), null);
  assert.equal(transform.deserialize(undefined), null);

  let deserializedData = transform.deserialize(testSerializedData);

  assert.equal(deserializedData[0].get('name'), testDeserializedData[0].get('name'));
  assert.equal(deserializedData[0].get('content_type'), testDeserializedData[0].get('content_type'));
  assert.equal(deserializedData[0].get('data'), testDeserializedData[0].get('data'));
  assert.equal(deserializedData[0].get('digest'), testDeserializedData[0].get('digest'));

  assert.equal(deserializedData[1].get('name'), testDeserializedData[1].get('name'));
  assert.equal(deserializedData[1].get('content_type'), testDeserializedData[1].get('content_type'));
  assert.equal(deserializedData[1].get('stub'), true);
  assert.equal(deserializedData[1].get('digest'), testDeserializedData[1].get('digest'));
  assert.equal(deserializedData[1].get('length'), testDeserializedData[1].get('length'));
});
{'fraction_non_alphanumeric': 0.16680743243243243, 'fraction_numerical': 0.01266891891891892, 'mean_word_length': 6.134036144578313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6600801', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1569, 'n_words': 231}