<commit_before>var expect = require('chai').expect;
var rewire = require('rewire');
var sinon  = require('sinon');
var mockEventList = require('./mocks/eventList.json');
var Promise = require('bluebird');
var AdministerCalendars = rewire('../services/AdministerCalendars');

describe('Administer Calendar Test', function CalendarTestSuite() {
  var calendar = AdministerCalendars.__get__('calendar');
  var listSpy = sinon.spy(AdministerCalendars.__get__('listEvents'));

  beforeEach(function setUp(done) {
    var jwtMock = {
      createJWT: function jwtFake() {
        return Promise.resolve('a secured client');
      }
    };

    AdministerCalendars.__set__('AdministerJWT', jwtMock);
    done();
  });

  it('should send an update to Google Calendar', function UserListParams(done) {
    var updateEvent = AdministerCalendars.__get__('updateEvent');
    var updateSpy = sinon.spy(calendar.events, 'update');
    var fakeResourceBody = {
      summary: 'testing',
      foo: 'bar'
    };

    // Since it will fail as this isn't an actual event
    updateEvent({ eventId: 'event1', calendarId: 'calendar1' }, fakeResourceBody)
      .catch(function updateError() {
        var expectedParams = {
          eventId: 'event1',
          calendarId: 'calendar1',
          resource: fakeResourceBody,
          auth: 'a secured client'
        };

        expect(updateSpy.calledWith(expectedParams)).to.be.true;
        done();
      });
  });

  it('should return a sync token', function syncTokenTest(done) {
    var mockFullSync = function sync() {
      return Promise.resolve(mockEventList);
    };<commit_msg>Add tear down for calendar spec<commit_after>var expect = require('chai').expect;
var rewire = require('rewire');
var sinon  = require('sinon');
var mockEventList = require('./mocks/eventList.json');
var Promise = require('bluebird');
var AdministerCalendars = rewire('../services/AdministerCalendars');

describe('Administer Calendar Test', function CalendarTestSuite() {
  var calendar = AdministerCalendars.__get__('calendar');
  var listSpy = sinon.spy(AdministerCalendars.__get__('listEvents'));
  let jwtRevert;

  beforeEach(function setUp(done) {
    var jwtMock = {
      createJWT: function jwtFake() {
        return Promise.resolve('a secured client');
      }
    };

    jwtRevert = AdministerCalendars.__set__('AdministerJWT', jwtMock);
    done();
  });

  afterEach(() => jwtRevert());

  it('should send an update to Google Calendar', function UserListParams(done) {
    var updateEvent = AdministerCalendars.__get__('updateEvent');
    var updateSpy = sinon.spy(calendar.events, 'update');
    var fakeResourceBody = {
      summary: 'testing',
      foo: 'bar'
    };

    // Since it will fail as this isn't an actual event
    updateEvent({ eventId: 'event1', calendarId: 'calendar1' }, fakeResourceBody)
      .catch(function updateError() {
        var expectedParams = {
          eventId: 'event1',
          calendarId: 'calendar1',
          resource: fakeResourceBody,
          auth: 'a secured client'
        };

        expect(updateSpy.calledWith(expectedParams)).to.be.true;
        done();
      });
  });

  it('should return a sync token', function syncTokenTest(done) {
    var mockFullSync = function sync() {
      return Promise.resolve(mockEventList);
    };
{'fraction_non_alphanumeric': 0.12974111980734498, 'fraction_numerical': 0.002408187838651415, 'mean_word_length': 3.502710027100271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6518517', 'n_tokens_mistral': 986, 'n_tokens_neox': 962, 'n_words': 230}