<commit_before>const { expect, knex, describe, beforeEach, afterEach, it, sinon } = require('../../../test-helper');
const snapshotRepository = require('../../../../lib/infrastructure/repositories/snapshot-repository');
const Snapshot = require('../../../../lib/domain/models/data/snapshot');

describe('Unit | Repository | SnapshotRepository', function() {

  const serializedUserProfile = {
    data: {
      type: 'users',
      id: 'user_id',
      attributes: {
        'first-name': 'Luke',
        'last-name': 'Skywalker',
        'total-pix-score': 128,
        'email': '<EMAIL>'
      },
      relationships: {
        competences: {
          data: [
            { type: 'competences', id: 'recCompA' },
            { type: 'competences', id: 'recCompB' }
          ]
        }
      },
    },
    included: [
      {
        type: 'areas',
        id: 'recAreaA',
        attributes: {
          name: 'area-name-1'
        }
      },
      {
        type: 'areas',
        id: 'recAreaB',
        attributes: {
          name: 'area-name-2'
        }
      },
      {
        type: 'competences',
        id: 'recCompA',
        attributes: {
          name: 'competence-name-1',
          index: '1.1',
          level: -1,
          'course-id': 'recBxPAuEPlTgt72q11'
        },
        relationships: {
          area: {
            data: {
              type: 'areas',
              id: 'recAreaA'
            }
          }
        }
      },
      {
        type: 'competences',
        id: 'recCompB',
        attributes: {
          name: 'competence-name-2',
          index: '1.2',
          level: 8,
          'pix-score': 128,
          'course-id': 'recBxPAuEPlTgt72q99'
        },
        relationships: {
          area: {
            data: {
              type: 'areas',
              id: 'recAreaB'
            }
          }
        }
      }
    ]
  };
  const snapshot = {
    organizationId: 150,
    score: 128,
    profile: JSON.stringify(serializedUserProfile)
  };

  beforeEach(() => {
    sinon.spy(Snapshot.prototype, 'save');
  });

  afterEach(() => {
    Snapshot.prototype.save.restore();
    knex('snapshots').delete();
  });

  it('should save a new snapshot', () => {
    // given

    const promise = snapshotRepository.save(snapshot);

    return promise.then(snapshotId => {
      expect(snapshotId).to.not.be.null;
      sinon.assert.calledOnce(Snapshot.prototype.save);
    });
  });
});<commit_msg>Add knex delete to snapshot repository<commit_after>const { expect, knex, describe, beforeEach, afterEach, after, it, sinon } = require('../../../test-helper');
const snapshotRepository = require('../../../../lib/infrastructure/repositories/snapshot-repository');
const Snapshot = require('../../../../lib/domain/models/data/snapshot');

describe('Unit | Repository | SnapshotRepository', function() {

  const serializedUserProfile = {
    data: {
      type: 'users',
      id: 'user_id',
      attributes: {
        'first-name': 'Luke',
        'last-name': 'Skywalker',
        'total-pix-score': 128,
        'email': '<EMAIL>'
      },
      relationships: {
        competences: {
          data: [
            { type: 'competences', id: 'recCompA' },
            { type: 'competences', id: 'recCompB' }
          ]
        }
      },
    },
    included: [
      {
        type: 'areas',
        id: 'recAreaA',
        attributes: {
          name: 'area-name-1'
        }
      },
      {
        type: 'areas',
        id: 'recAreaB',
        attributes: {
          name: 'area-name-2'
        }
      },
      {
        type: 'competences',
        id: 'recCompA',
        attributes: {
          name: 'competence-name-1',
          index: '1.1',
          level: -1,
          'course-id': 'recBxPAuEPlTgt72q11'
        },
        relationships: {
          area: {
            data: {
              type: 'areas',
              id: 'recAreaA'
            }
          }
        }
      },
      {
        type: 'competences',
        id: 'recCompB',
        attributes: {
          name: 'competence-name-2',
          index: '1.2',
          level: 8,
          'pix-score': 128,
          'course-id': 'recBxPAuEPlTgt72q99'
        },
        relationships: {
          area: {
            data: {
              type: 'areas',
              id: 'recAreaB'
            }
          }
        }
      }
    ]
  };
  const snapshot = {
    organizationId: 150,
    score: 128,
    profile: JSON.stringify(serializedUserProfile)
  };

  after(() => {
    return knex('snapshots').delete();
  });

  beforeEach(() => {
    sinon.spy(Snapshot.prototype, 'save');
  });

  afterEach(() => {
    Snapshot.prototype.save.restore();
    knex('snapshots').delete();
  });

  it('should save a new snapshot', () => {
    // given

    const promise = snapshotRepository.save(snapshot);

    return promise.then(snapshotId => {
      expect(snapshotId).to.not.be.null;
      sinon.assert.calledOnce(Snapshot.prototype.save);
    });
  });
});
{'fraction_non_alphanumeric': 0.16286514605842337, 'fraction_numerical': 0.012004801920768308, 'mean_word_length': 1.5544200306591722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '6273317', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1552, 'n_words': 269}