{"size": 2559, "ext": "js", "max_stars_repo_path": "test/attachment.js", "max_stars_repo_name": "Datahero/desk.js", "max_stars_repo_stars_event_min_datetime": "2015-07-29T18:31:03.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-22T06:54:12.000Z", "max_issues_repo_path": "test/attachment.js", "max_issues_repo_name": "Datahero/desk.js", "max_issues_repo_issues_event_min_datetime": "2015-01-15T18:32:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T19:28:33.000Z", "max_forks_repo_path": "test/attachment.js", "max_forks_repo_name": "Datahero/desk.js", "max_forks_repo_forks_event_min_datetime": "2015-04-09T13:22:41.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-23T17:26:16.000Z"}
{"max_stars_count": 5, "max_issues_count": 11, "max_forks_count": 6, "avg_line_length": 29.4137931034, "max_line_length": 88, "alphanum_fraction": 0.5677999218}

var desk = require('../')
  , should = require('should')
  , replay = require('replay')
  , fs = require('fs')
  ;

replay.fixtures = __dirname + '/fixtures';
replay.mode = 'record';
replay.request_headers = [/^accept/, /^content-type/, /^host/, /^if-/, /^x-/];

try {
  config = require('../config');
} catch (err) {
  config = {
    subdomain: 'devel',
    username: 'devel@example.com',
    password: '12345',
    consumerKey: 'your-consumer-key',
    consumerSecret: 'your-consumer-secret',
    token: 'your-token',
    tokenSecret: 'your-token-secret'
  }
}

function createClient() {
  return desk.createClient({
    subdomain: config.subdomain ,
    username: config.username,
    password: config.password
  })
}

// check if the hack works
describe('Attachment', function() {
  describe('create', function() {
    it('creates a new attachment on a case', function(done) {
      var client = createClient();
      client.cases(function(err, cases) {
        cases[0].attachments().create({
          file_name: 'GlasKunst.jpg',
          content_type: 'image/jpeg',
          content: fs.readFileSync(__dirname + '/fixtures/attachment.jpg', 'base64')
        }, function(err, attachment) {
          attachment.getFileName().should.equal('GlasKunst.jpg');
          attachment.getUrl().should.not.equal('');
          done();
        });
      });
    })
  })

  describe('delete', function() {
    it('deletes an attachment from a case - currently not working', function(done) {
      var client = createClient();
      client.cases(function(err, cases) {
        cases[0].attachments(function(err, attachments) {
          attachments[0].destroy(function(err) {
            should.not.exist(err);
            done();
          })
        })
      })
    })
  })

  // describe('update', function() {
  //   it('updates attachments on cases', function(done) {
  //     var client = createClient();
  //     client.cases(function(err, cases) {
  //       // cases[0] is a phone call
  //       cases[1].attachments().create({
  //         body: 'some text for this attachment',
  //         direction: 'out',
  //         status: 'draft'
  //       }, function(err, attachment) {
  //         attachment.setBody('some other text for this attachment');
  //         attachment.update(function(err, attachment) {
  //           attachment.getBody().should.equal('some other text for this attachment');
  //           attachment.getDirection().should.equal('out');
  //           done();
  //         });
  //       });
  //     });
  //   })
  // })
})