<commit_before>'use strict';

var getSpyableShippo = require('./testUtils').getSpyableShippo;
var expect = require('chai').expect;

describe('Resourcetest', function() {

    var shippo;

    describe('apiVersionSet', function() {

        before(function() {
            shippo = getSpyableShippo();
        });

        it('tests that the version header is properly set', function() {
            shippo.set('version', 'sample_version')
            expect(shippo.address._get_headers('mock_request')['Shippo-API-Version']).to.equal('sample_version');
        });

    });

    describe('authorization tokens', function() {

        describe('on init', function() {

            it('correctly uses a shippoToken by default', function () {
                shippo = getSpyableShippo('mockShippoToken');
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken mockShippoToken');
            });

            it('correctly uses an explicit shippoToken', function () {
                shippo = getSpyableShippo({shippoToken: 'another<PASSWORD>Token'});
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken anotherMockShippoToken');
            })

            it('correctly uses an explicit oauthToken', function () {
                shippo = getSpyableShippo({oauthToken: 'mockOauthToken'});
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('Bearer mockOauthToken');
            })

            it('throws an error if both tokens are provided', function () {
                expect(function () {
                    getSpyableShippo({shippoToken: 'mock<PASSWORD>1', oauthToken: 'mock<PASSWORD>2'});
                }).to.throw('Ambiguous authentication credentials');
            })

        });

        describe('setToken method', function() {

            it('correctly sets shippoToken', function() {
                shippo = getSpyableShippo({ oauthToken: 'mockOauthToken' });
                shippo.setToken({ shippoToken: 'mock<PASSWORD>Token' });
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken mockShippoToken');
            })

            it('correctly sets oauthToken', function() {
                shippo = getSpyableShippo({shippoToken: '<PASSWORD>'});
                shippo.setToken({ oauthToken: '<PASSWORD>' });
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('Bearer mockOauthToken');
            })
        })

    });

    describe.only('_responseHandler', function() {

        describe('when a json parse error is caught', function() {

            it('should return a generic error with full error data', function() {
                var expectedErrorData = {
                    detail: '',
                    path: '/testing',
                    statusCode: 429,
                    message: 'Invalid JSON received from the Shippo API',
                    type: 'ShippoAPIError'
                };

                var fakeRequest = {
                    path: '/testing',
                };

                shippo = getSpyableShippo({ oauthToken: '<PASSWORD>' });
                const responseCallback = shippo.address._responseHandler(fakeRequest, function(error, _) {
                    for (var k in Object.keys(error)) {
                        expect(expectedErrorData[k]).to.eql(error[k]);
                    }<commit_msg>Remove .only from test<commit_after>'use strict';

var getSpyableShippo = require('./testUtils').getSpyableShippo;
var expect = require('chai').expect;

describe('Resourcetest', function() {

    var shippo;

    describe('apiVersionSet', function() {

        before(function() {
            shippo = getSpyableShippo();
        });

        it('tests that the version header is properly set', function() {
            shippo.set('version', 'sample_version')
            expect(shippo.address._get_headers('mock_request')['Shippo-API-Version']).to.equal('sample_version');
        });

    });

    describe('authorization tokens', function() {

        describe('on init', function() {

            it('correctly uses a shippoToken by default', function () {
                shippo = getSpyableShippo('mockShippoToken');
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken mockShippoToken');
            });

            it('correctly uses an explicit shippoToken', function () {
                shippo = getSpyableShippo({shippoToken: 'anotherMockShippoToken'});
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken anotherMockShippoToken');
            })

            it('correctly uses an explicit oauthToken', function () {
                shippo = getSpyableShippo({oauthToken: 'mockOauthToken'});
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('Bearer mockOauthToken');
            })

            it('throws an error if both tokens are provided', function () {
                expect(function () {
                    getSpyableShippo({shippoToken: '<PASSWORD>', oauthToken: '<PASSWORD>'});
                }).to.throw('Ambiguous authentication credentials');
            })

        });

        describe('setToken method', function() {

            it('correctly sets shippoToken', function() {
                shippo = getSpyableShippo({ oauthToken: 'mockOauthToken' });
                shippo.setToken({ shippoToken: 'mockShippoToken' });
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('ShippoToken mockShippoToken');
            })

            it('correctly sets oauthToken', function() {
                shippo = getSpyableShippo({shippoToken: 'mockShippoToken'});
                shippo.setToken({ oauthToken: 'mockOauthToken' });
                expect(shippo.address._get_headers('mock_request')['Authorization']).to.equal('Bearer mockOauthToken');
            })
        })

    });

    describe('_responseHandler', function() {

        describe('when a json parse error is caught', function() {

            it('should return a generic error with full error data', function() {
                var expectedErrorData = {
                    detail: '',
                    path: '/testing',
                    statusCode: 429,
                    message: 'Invalid JSON received from the Shippo API',
                    type: 'ShippoAPIError'
                };

                var fakeRequest = {
                    path: '/testing',
                };

                shippo = getSpyableShippo({ oauthToken: '<PASSWORD>' });
                const responseCallback = shippo.address._responseHandler(fakeRequest, function(error, _) {
                    for (var k in Object.keys(error)) {
                        expect(expectedErrorData[k]).to.eql(error[k]);
                    }
{'fraction_non_alphanumeric': 0.12893126512025047, 'fraction_numerical': 0.0011384659171766046, 'mean_word_length': 2.1772151898734178, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3672033', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1858, 'n_words': 339}