<commit_before>var angular = require('angular');
require('angular-mocks');

describe('csHandleError Service', () => {
  beforeEach(angular.mock.module('fightApp'));
  it('should return a function', angular.mock.inject((csHandleError) => {
    expect(typeof csHandleError).toBe('function');
  }));
  it('should add an error to the errors array', angular.mock.inject((csHandleError) => {
    var testArr = [];
    csHandleError(testArr, 'test message')();
    expect(testArr.length).toBe(1);
    expect(testArr[0] instanceof Error).toBe(true);
    expect(testArr[0].message).toBe('test message');
  }));
});

describe('csResouce Service', () => {
  beforeEach(angular.mock.module('fightApp'));

  it('should return a function', angular.mock.inject((csResource) => {
    expect(typeof csResource).toBe('function');
  }));

  it('should add a dinosaur to array', angular.mock.inject((csResource, $httpBackend) => {
    $httpBackend.expectPOST('localhost:8000/api/dinosaurs', { name: '<NAME>' })
    .respond(200, { name: 'another test', _id: 0 });
    var baseUrl = 'localhost:8000';
    var testArr = [];
    var errorsArr = [];
    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');
    testRemote.save({ name: '<NAME>' });
    $httpBackend.flush();
    expect(testArr.length).toBe(1);
    expect(errorsArr.length).toBe(0);
    expect(testArr[0].name).toBe('another test');
  }));

  it('should have update functionality', angular.mock.inject((csResource, $httpBackend, $q) => {
    var baseUrl = 'localhost:8000';
    var testDino = { name: '<NAME>', _id: 1 };
    var testArr = [testDino];
    var errorsArr = [];

    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');

    $httpBackend.expectPUT('localhost:8000/api/dinosaurs/1', testDino)
    .respond(200);

    var result = testRemote.update(testDino);
    $httpBackend.flush();
    expect(testArr.length).toBe(1);
    expect(errorsArr.length).toBe(0);
    expect(result instanceof $q).toBe(true);
  }));
});<commit_msg>add testing for resource service<commit_after>var angular = require('angular');
require('angular-mocks');

describe('csHandleError Service', () => {
  beforeEach(angular.mock.module('fightApp'));
  it('should return a function', angular.mock.inject((csHandleError) => {
    expect(typeof csHandleError).toBe('function');
  }));
  it('should add an error to the errors array', angular.mock.inject((csHandleError) => {
    var testArr = [];
    csHandleError(testArr, 'test message')();
    expect(testArr.length).toBe(1);
    expect(testArr[0] instanceof Error).toBe(true);
    expect(testArr[0].message).toBe('test message');
  }));
});

describe('csResouce Service', () => {
  beforeEach(angular.mock.module('fightApp'));

  it('should return a function', angular.mock.inject((csResource) => {
    expect(typeof csResource).toBe('function');
  }));

  it('should add a dinosaur to array', angular.mock.inject((csResource, $httpBackend) => {
    $httpBackend.expectPOST('http://localhost:8000/api/dinosaurs', {
        name: '<NAME>'
      })
      .respond(200, {
        name: '<NAME>',
        _id: 0
      });
    var baseUrl = 'http://localhost:8000';
    var testArr = [];
    var errorsArr = [];
    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');
    testRemote.save({
      name: '<NAME>'
    });
    $httpBackend.flush();
    expect(testArr.length).toBe(1);
    expect(errorsArr.length).toBe(0);
    expect(testArr[0].name).toBe('another test');
  }));

  it('should have update functionality', angular.mock.inject((csResource, $httpBackend, $q) => {
    var baseUrl = 'http://localhost:8000';
    var testDino = {
      name: '<NAME>',
      _id: 1
    };
    var testArr = [testDino];
    var errorsArr = [];

    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');

    $httpBackend.expectPUT('http://localhost:8000/api/dinosaurs/1', testDino)
      .respond(200);

    var result = testRemote.update(testDino);
    $httpBackend.flush();
    expect(testArr.length).toBe(1);
    expect(errorsArr.length).toBe(0);
    expect(result instanceof $q).toBe(true);
  }));

  it('should get all the resources', angular.mock.inject((csResource, $httpBackend) => {
    $httpBackend.expectGET('http://localhost:8000/api/dinosaurs')
      .respond(200, [{
        name: '<NAME>'
      }]);

    var testArr = [{}, {}, {}, {}];
    var errorsArr = [];
    var baseUrl = 'http://localhost:8000';
    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');

    testRemote.getAll();
    $httpBackend.flush();
    expect(testArr.length).toBe(1);
    expect(testArr[0].name).toBe('<NAME>');
  }));

  it('should remove a resource', angular.mock.inject((csResource, $httpBackend) => {
    $httpBackend.expectDELETE('http://localhost:8000/api/dinosaurs/1').respond(200);
    var testArr = [{
      name: 'testy',
      _id: 1
    }];
    var baseUrl = 'http://localhost:8000';
    var errorsArr = [];
    var testRemote = new csResource(testArr, errorsArr, baseUrl + '/api/dinosaurs');
    testRemote.remove(testArr[0]);
    $httpBackend.flush();
    expect(testArr.length).toBe(0);
  }));
});
{'fraction_non_alphanumeric': 0.1835637480798771, 'fraction_numerical': 0.01804915514592934, 'mean_word_length': 3.9327651515151514, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 28, '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': '5495077', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1643, 'n_words': 306}