<commit_before>/*
 * Copyright (c) 2013 <NAME>. All rights reserved.
 */

var assert = require('assert');
var should = require('should');
var sinon = require('sinon');
var _ = require('underscore');
var index = require('../lib/index');
var restify = require('restify');

describe('test', function () {
    it('_convertToSwagger', function (done) {
        index._convertToSwagger.should.have.type('function');
        index._convertToSwagger('hello/:firstParam/:secondParam').should.equal('hello/{firstParam}/{secondParam}');
        index._convertToSwagger('hello/:firstParam/test/:secondParam').should.equal('hello/{firstParam}/test/{secondParam}');
        index._convertToSwagger('hello/:firstParam/test/:secondParam/asdf').should.equal('hello/{firstParam}/test/{secondParam}/asdf');
        done();
    });

    it('_mapToSwaggerType', function (done) {
        index._mapToSwaggerType.should.have.type('function');
        index._mapToSwaggerType({ isJSONObject: true }).should.equal('object');
        index._mapToSwaggerType({ isJSONArray: true }).should.equal('array');
        index._mapToSwaggerType({ isDate: true }).should.equal('dateTime');
        index._mapToSwaggerType({ isFloat: true }).should.equal('float');
        index._mapToSwaggerType({ isBoolean: true }).should.equal('boolean');
        index._mapToSwaggerType({ swaggerType: 'asdf' }).should.equal('asdf');
        index._mapToSwaggerType({ isInt: true }).should.equal('integer');
        index._mapToSwaggerType({  }).should.equal('string');
        index._mapToSwaggerType('asdfasdf').should.equal('string');
        index._mapToSwaggerType(null).should.equal('string');
        done();
    });

    it('configure', function (done) {
        var server = sinon.stub(index.swagger, 'configure', function (myServer, myOptions) {
            myServer.should.equal(server);
            myOptions.discoveryUrl.should.exist;
            myOptions.abc.should.be.ok;
        });

        index.configure(server, { abc: true });
        server.called.should.be.ok;
        server.restore();
        done();
    });

    it('findOrCreateResource', function (done) {
        index.swagger.resources = [];

        var resource = '/test';
        var options = {};

        var server = sinon.stub(index.swagger, 'createResource', function (myResource, myOptions) {
            myResource.should.equal(resource);
            myOptions.should.equal(options);
            return true;
        });

        index.findOrCreateResource(resource, options).should.be.ok;
        server.called.should.be.ok;
        server.calledOnce.should.be.ok;

        var resourceObj = { path: resource };<commit_msg>Fix tests so they are autonomous.<commit_after>/*
 * Copyright (c) 2013 <NAME>. All rights reserved.
 */

var assert = require('assert');
var should = require('should');
var sinon = require('sinon');
var _ = require('underscore');
var index = require('../lib/index');
var restify = require('restify');

describe('test', function () {
    beforeEach(function() {
        index.swagger.resources = [];
    });

    it('_convertToSwagger', function (done) {
        index._convertToSwagger.should.have.type('function');
        index._convertToSwagger('hello/:firstParam/:secondParam').should.equal('hello/{firstParam}/{secondParam}');
        index._convertToSwagger('hello/:firstParam/test/:secondParam').should.equal('hello/{firstParam}/test/{secondParam}');
        index._convertToSwagger('hello/:firstParam/test/:secondParam/asdf').should.equal('hello/{firstParam}/test/{secondParam}/asdf');
        done();
    });

    it('_mapToSwaggerType', function (done) {
        index._mapToSwaggerType.should.have.type('function');
        index._mapToSwaggerType({ isJSONObject: true }).should.equal('object');
        index._mapToSwaggerType({ isJSONArray: true }).should.equal('array');
        index._mapToSwaggerType({ isDate: true }).should.equal('dateTime');
        index._mapToSwaggerType({ isFloat: true }).should.equal('float');
        index._mapToSwaggerType({ isBoolean: true }).should.equal('boolean');
        index._mapToSwaggerType({ swaggerType: 'asdf' }).should.equal('asdf');
        index._mapToSwaggerType({ isInt: true }).should.equal('integer');
        index._mapToSwaggerType({  }).should.equal('string');
        index._mapToSwaggerType('asdfasdf').should.equal('string');
        index._mapToSwaggerType(null).should.equal('string');
        done();
    });

    it('configure', function (done) {
        var server = sinon.stub(index.swagger, 'configure', function (myServer, myOptions) {
            myServer.should.equal(server);
            myOptions.discoveryUrl.should.exist;
            myOptions.abc.should.be.ok;
        });

        index.configure(server, { abc: true });
        server.called.should.be.ok;
        server.restore();
        done();
    });

    it('findOrCreateResource', function (done) {


        var resource = '/test';
        var options = {};

        var server = sinon.stub(index.swagger, 'createResource', function (myResource, myOptions) {
            myResource.should.equal(resource);
            myOptions.should.equal(options);
            return true;
        });

        index.findOrCreateResource(resource, options).should.be.ok;
        server.called.should.be.ok;
        server.calledOnce.should.be.ok;

        var resourceObj = { path: resource };
{'fraction_non_alphanumeric': 0.16246290801186944, 'fraction_numerical': 0.001483679525222552, 'mean_word_length': 3.2001557632398754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7514196', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1540, 'n_words': 244}