/* eslint-env jasmine */
var nock = require('nock')
var VoucherifyClient = require('./client-loader')
var fixtures = require('./fixtures')
var reqWithBody = fixtures.reqWithBody
nock.disableNetConnect()

describe('Events API', function () {
  var client = new VoucherifyClient({
    applicationId: 'node-sdk-test-id',
    clientSecretKey: 'node-sdk-test-secret'
  })

  it('should send event (deprecated)', function (done) {
    var server = nock('https://api.voucherify.io', reqWithBody)
      .post('/v1/events', {
        event: 'custom event name',
        customer: {
          id: 'cust_test-id',
          source_id: 's_test-id',
          name: 'customer name'
        },
        metadata: {
          lang: 'en',
          test: true
        }
      })
      .reply(200, true)

    client.events.track('custom event name', {
      lang: 'en',
      test: true
    }, {
      id: 'cust_test-id',
      source_id: 's_test-id',
      name: 'customer name'
    })
      .then(function () {
        server.done()
        done()
      })
  })

  it('should create event', function (done) {
    var server = nock('https://api.voucherify.io', reqWithBody)
      .post('/v1/events', {
        event: 'custom event name',
        customer: {
          id: 'cust_test-id',
          source_id: 's_test-id',
          name: 'customer name'
        },
        metadata: {
          lang: 'en',
          test: true
        }
      })
      .reply(200, true)

    client.events.create('custom event name', {
      customer: {
        id: 'cust_test-id',
        source_id: 's_test-id',
        name: 'customer name'
      },
      metadata: {
        lang: 'en',
        test: true
      }
    })
      .then(function () {
        server.done()
        done()
      })
  })

  it('should create event (callback)', function (done) {
    var server = nock('https://api.voucherify.io', reqWithBody)
      .post('/v1/events', {
        event: 'custom event name',
        customer: {
          id: 'cust_test-id',
          source_id: 's_test-id',
          name: 'customer name'
        },
        metadata: {
          lang: 'en',
          test: true
        }
      })
      .reply(200, true)

    client.events.create('custom event name', {
      customer: {
        id: 'cust_test-id',
        source_id: 's_test-id',
        name: 'customer name'
      },
      metadata: {
        lang: 'en',
        test: true
      }
    }, function (err) {
      expect(err).toBeNull()
      server.done()
      done()
    })
  })
})

@@ -2509,12 +2509,1771 @@
  %7D)%0A  %7D)
+%0A%0A  it('should create event for loyalty', function (done) %7B%0A    var server = nock('https://api.voucherify.io', reqWithBody)%0A      .post('/v1/events', %7B%0A        event: 'custom event name',%0A        customer: %7B%0A          id: 'cust_test-id',%0A          source_id: 's_test-id',%0A          name: 'customer name'%0A        %7D,%0A        loyalty: %7B%0A          code: 'loyalty_code_test-id'%0A        %7D,%0A        metadata: %7B%0A          lang: 'en',%0A          test: true%0A        %7D%0A      %7D)%0A      .reply(200, true)%0A%0A    client.events.create('custom event name', %7B%0A      customer: %7B%0A        id: 'cust_test-id',%0A        source_id: 's_test-id',%0A        name: 'customer name'%0A      %7D,%0A      loyalty: %7B%0A        code: 'loyalty_code_test-id'%0A      %7D,%0A      metadata: %7B%0A        lang: 'en',%0A        test: true%0A      %7D%0A    %7D)%0A      .then(function () %7B%0A        server.done()%0A        done()%0A      %7D)%0A  %7D)%0A%0A  it('should create event for loyalty (callback)', function (done) %7B%0A    var server = nock('https://api.voucherify.io', reqWithBody)%0A      .post('/v1/events', %7B%0A        event: 'custom event name',%0A        customer: %7B%0A          id: 'cust_test-id',%0A          source_id: 's_test-id',%0A          name: 'customer name'%0A        %7D,%0A        loyalty: %7B%0A          code: 'loyalty_code_test-id'%0A        %7D,%0A        metadata: %7B%0A          lang: 'en',%0A          test: true%0A        %7D%0A      %7D)%0A      .reply(200, true)%0A%0A    client.events.create('custom event name', %7B%0A      customer: %7B%0A        id: 'cust_test-id',%0A        source_id: 's_test-id',%0A        name: 'customer name'%0A      %7D,%0A      loyalty: %7B%0A        code: 'loyalty_code_test-id'%0A      %7D,%0A      metadata: %7B%0A        lang: 'en',%0A        test: true%0A      %7D%0A    %7D, function (err) %7B%0A      expect(err).toBeNull()%0A      server.done()%0A      done()%0A    %7D)%0A  %7D)
 %0A%7D)%0A

Add loyalty test case for events.create