<commit_before>const simple = require("simple-mock");
const test = require("tap").test;

const abandon = require(`${__dirname}/../../src/commands/abandon.js`);

const payload = {
  repository: {
    owner: {
      login: "zulip"
    },
    name: "zulipbot"
  },
  issue: {
    number: "69",
    assignees: [{
      login: "octocat"
    }]
  }
};

const client = {
  issues: {
    createComment: () => {},
    removeAssigneesFromIssue: () => {}
  }
};

test("Reject if commenter isn't an assignee", async t => {
  const commenter = "octokitten";

  const error = "**ERROR:** You have not claimed this issue to work on yet.";
  const request = simple.mock(client.issues, "createComment").resolveWith({
    data: {
      body: error
    }
  });

  const response = await abandon.run.apply(client, [payload, commenter]);

  t.equals(request.lastCall.arg.owner, "zulip");
  t.equals(request.lastCall.arg.repo, "zulipbot");
  t.equals(request.lastCall.arg.number, "69");
  t.equals(response.data.body, error);

  simple.restore();
  t.end();
});

test("Remove if commenter is assigned", async t => {
  const commenter = "octocat";

  const request = simple.mock(client.issues, "removeAssigneesFromIssue")
    .resolveWith({
      data: {
        assignees: []
      }
    });

  const response = await abandon.run.apply(client, [payload, commenter]);

  abandon.run.apply(client, [payload, commenter]);

  t.equals(request.lastCall.arg.owner, "zulip");
  t.equals(request.lastCall.arg.repo, "zulipbot");
  t.equals(request.lastCall.arg.number, "69");
  t.same(request.lastCall.arg.assignees, ["octocat"]);
  t.same(response.data.assignees, []);

  simple.restore();
  t.end();
});<commit_msg>tests: Improve abandon command test coverage.<commit_after>const simple = require("simple-mock");
const test = require("tap").test;

const client = require(`${__dirname}/../../src/client.js`);
const abandon = require(`${__dirname}/../../src/commands/abandon.js`);

const payload = {
  repository: {
    owner: {
      login: "zulip"
    },
    name: "zulipbot"
  },
  issue: {
    number: 69,
    assignees: [{
      login: "octocat"
    }]
  }
};

test("Reject if commenter isn't an assignee", async t => {
  const commenter = "octokitten";

  const error = "**ERROR:** You have not claimed this issue to work on yet.";
  const request = simple.mock(client.issues, "createComment").resolveWith({
    data: {
      body: error
    }
  });

  const response = await abandon.run.call(client, payload, commenter);

  t.equals(request.lastCall.arg.owner, "zulip");
  t.equals(request.lastCall.arg.repo, "zulipbot");
  t.equals(request.lastCall.arg.number, 69);
  t.equals(request.lastCall.arg.body, error);
  t.equals(response.data.body, error);

  simple.restore();
  t.end();
});

test("Remove if commenter is assigned", async t => {
  const commenter = "octocat";

  const request = simple.mock(client.issues, "removeAssigneesFromIssue")
    .resolveWith({
      data: {
        assignees: []
      }
    });

  const response = await abandon.run.call(client, payload, commenter);

  t.equals(request.lastCall.arg.owner, "zulip");
  t.equals(request.lastCall.arg.repo, "zulipbot");
  t.equals(request.lastCall.arg.number, 69);
  t.same(request.lastCall.arg.assignees, ["octocat"]);
  t.same(response.data.assignees, []);

  simple.restore();
  t.end();
});
{'fraction_non_alphanumeric': 0.17629452259802456, 'fraction_numerical': 0.0035917390002993114, 'mean_word_length': 3.4979811574697175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4592638', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1122, 'n_words': 226}