<commit_before>var nock = require("nock");
var Client = require("../lib/client");

var baseUrl = "https://api.catapult.inetwork.com";

describe("Client", function () {

	var accountResponse = {
		balance     : "20.00",
		accountType : "pre-pay"
	};

	before(function () {
		nock.disableNetConnect();
	});

	after(function () {
		nock.enableNetConnect();
	});

	describe("using default options", function () {
		var client;

		before(function () {
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey"
			});

			nock(baseUrl)
				.persist()
				.get("/v1/users/fakeUserId/account")
				.reply(200, accountResponse);
		});

		after(function () {
			nock.cleanAll();
		});

		it("should make requests to the default baseUrl", function () {
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				res.body.should.eql(accountResponse);
			});
		});
	});

	describe("using custom options", function () {
		var client;
		var oldBaseUrl;

		before(function () {
			oldBaseUrl = baseUrl;
			baseUrl = "https://stage.catapult.inetwork.com";
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey",
				baseUrl  : baseUrl
			});
		});

		after(function () {
			nock.cleanAll();
			baseUrl = oldBaseUrl;
		});

		it("should make requests to the custom baseUrl", function () {
			var accountResponse = {
				balance     : "20.00",
				accountType : "pre-pay"
			};

			nock(baseUrl).get("/v1/users/fakeUserId/account").reply(200, accountResponse);
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				res.body.should.eql(accountResponse);
			});
		});

	});

	describe("in error cases", function () {
		var client;

		before(function () {
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey"
			});

			nock(baseUrl)
				.persist()
				.get("/v1/users/fakeUserId/account")
				.reply(401, { message : "Something bad happened..." })
				.get("/v1/users/fakeUserId/unknown")
				.reply(404)
				.get("/v1/users/fakeUserId/unknown2")
				.reply(404, {});
		});

		after(function () {
			nock.cleanAll();
		});

		it("should throw exceptions on unexpected HTTP responses", function () {
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				done("It should have thrown an exception!");
			}).catch(function (err) {
				err.statusCode.should.equal(401);
				err.message.should.equal("Something bad happened...");
			});
		});

		it("should throw exceptions on unexpected HTTP responses with no response body", function () {
			return client.makeRequest({
				path : "unknown"
			}).then(function (res) {
				done("It should have thrown an exception!");
			}).catch(function (err) {
				err.statusCode.should.equal(404);
				err.message.should.equal("");
			});
		});

		it("should throw exceptions on unexpected HTTP responses with an empty response body", function () {
			return client.makeRequest({
				path : "unknown2"
			}).then(function (res) {
				done("It should have thrown an exception!");
			}).catch(function (err) {<commit_msg>Changed tests to throw new Error instead of call Done with argument<commit_after>var nock = require("nock");
var Client = require("../lib/client");

var baseUrl = "https://api.catapult.inetwork.com";

describe("Client", function () {

	var accountResponse = {
		balance     : "20.00",
		accountType : "pre-pay"
	};

	before(function () {
		nock.disableNetConnect();
	});

	after(function () {
		nock.enableNetConnect();
	});

	describe("using default options", function () {
		var client;

		before(function () {
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey"
			});

			nock(baseUrl)
				.persist()
				.get("/v1/users/fakeUserId/account")
				.reply(200, accountResponse);
		});

		after(function () {
			nock.cleanAll();
		});

		it("should make requests to the default baseUrl", function () {
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				res.body.should.eql(accountResponse);
			});
		});
	});

	describe("using custom options", function () {
		var client;
		var oldBaseUrl;

		before(function () {
			oldBaseUrl = baseUrl;
			baseUrl = "https://stage.catapult.inetwork.com";
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey",
				baseUrl  : baseUrl
			});
		});

		after(function () {
			nock.cleanAll();
			baseUrl = oldBaseUrl;
		});

		it("should make requests to the custom baseUrl", function () {
			var accountResponse = {
				balance     : "20.00",
				accountType : "pre-pay"
			};

			nock(baseUrl).get("/v1/users/fakeUserId/account").reply(200, accountResponse);
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				res.body.should.eql(accountResponse);
			});
		});

	});

	describe("in error cases", function () {
		var client;

		before(function () {
			client = new Client({
				userId   : "fakeUserId",
				apiToken : "fakeApiToken",
				apiKey   : "fakeApiKey"
			});

			nock(baseUrl)
				.persist()
				.get("/v1/users/fakeUserId/account")
				.reply(401, { message : "Something bad happened..." })
				.get("/v1/users/fakeUserId/unknown")
				.reply(404)
				.get("/v1/users/fakeUserId/unknown2")
				.reply(404, {});
		});

		after(function () {
			nock.cleanAll();
		});

		it("should throw exceptions on unexpected HTTP responses", function () {
			return client.makeRequest({
				path : "account"
			}).then(function (res) {
				throw new Error("It should have thrown an exception!");
			}).catch(function (err) {
				err.statusCode.should.equal(401);
				err.message.should.equal("Something bad happened...");
			});
		});

		it("should throw exceptions on unexpected HTTP responses with no response body", function () {
			return client.makeRequest({
				path : "unknown"
			}).then(function (res) {
				throw new Error("It should have thrown an exception!");
			}).catch(function (err) {
				err.statusCode.should.equal(404);
				err.message.should.equal("");
			});
		});

		it("should throw exceptions on unexpected HTTP responses with an empty response body", function () {
			return client.makeRequest({
				path : "unknown2"
			}).then(function (res) {
				throw new Error("It should have thrown an exception!");
			}).catch(function (err) {
{'fraction_non_alphanumeric': 0.1642691415313225, 'fraction_numerical': 0.011136890951276101, 'mean_word_length': 3.139564660691421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '6095399', 'n_tokens_mistral': 2517, 'n_tokens_neox': 2043, 'n_words': 459}