<commit_before>/*global describe, it, expect, before, beforeEach, afterEach, runs, waitsFor */
// Set different port for testing
process.env.PORT = 8000;
process.env.NODE_ENV = 'test';

var request = require('request').defaults({json: true});
var server = require('../server');
var mongoose = require('mongoose');
var Group = mongoose.model('Group');
var User = mongoose.model('User');

var testData = {
    user: { email: '<EMAIL>', password: 'password' },
    groups: [
        { name: "innebandy!" },
        { name: "ostprovning" },
        { name: "coding jam" },
        { name: "spelkväll" }
    ]
};

var baseEndpoint = 'http://localhost:' + process.env.PORT + '/api/';
var groupsEndpoint = baseEndpoint + 'groups';

describe(groupsEndpoint, function () {
    var testUser = null;
    var testGroups = null;

    beforeEach(function () {
        var done = false;

        runs(function () {
            Group.remove({}, function (err) {
                if (err) {
                    console.log(err);
                }
                Group.create(testData.groups, function (err) {
                    if (err) {
                        console.log(err);
                    }
                    testGroups = Array.prototype.slice.call(arguments, 1);
                    done = true;
                });
            });
        });

        waitsFor(function () {
            return done;
        });
    });

    describe('not authenticated', function () {
        function testUnauthorized(cb) {
            it('should return unauthorized', function (done) {
                cb(function (err, resp) {
                    expect(err).toBeFalsy();
                    expect(resp.statusCode).toEqual(401);
                    done();
                });
            });
        }

        describe('get', function () {
            testUnauthorized(function(cb) {
                request(groupsEndpoint, cb);
            });
        });

        describe('get /:key', function () {
            testUnauthorized(function(cb) {
                var testGroup = testGroups[0];
                request(groupsEndpoint + '/' + testGroup.key, cb);
            });
        });

        describe('post', function() {
           testUnauthorized(function(cb) {
               request.post(groupsEndpoint, cb);
           })
        });

        describe('put /:key', function() {
            testUnauthorized(function(cb) {
                var testGroup = testGroups[0];
                request.put(groupsEndpoint + '/' + testGroup.key, cb);
            });
        });<commit_msg>Damn it, missed a semicolon...<commit_after>/*global describe, it, expect, before, beforeEach, afterEach, runs, waitsFor */
// Set different port for testing
process.env.PORT = 8000;
process.env.NODE_ENV = 'test';

var request = require('request').defaults({json: true});
var server = require('../server');
var mongoose = require('mongoose');
var Group = mongoose.model('Group');
var User = mongoose.model('User');

var testData = {
    user: { email: '<EMAIL>', password: 'password' },
    groups: [
        { name: "innebandy!" },
        { name: "ostprovning" },
        { name: "coding jam" },
        { name: "spelkväll" }
    ]
};

var baseEndpoint = 'http://localhost:' + process.env.PORT + '/api/';
var groupsEndpoint = baseEndpoint + 'groups';

describe(groupsEndpoint, function () {
    var testUser = null;
    var testGroups = null;

    beforeEach(function () {
        var done = false;

        runs(function () {
            Group.remove({}, function (err) {
                if (err) {
                    console.log(err);
                }
                Group.create(testData.groups, function (err) {
                    if (err) {
                        console.log(err);
                    }
                    testGroups = Array.prototype.slice.call(arguments, 1);
                    done = true;
                });
            });
        });

        waitsFor(function () {
            return done;
        });
    });

    describe('not authenticated', function () {
        function testUnauthorized(cb) {
            it('should return unauthorized', function (done) {
                cb(function (err, resp) {
                    expect(err).toBeFalsy();
                    expect(resp.statusCode).toEqual(401);
                    done();
                });
            });
        }

        describe('get', function () {
            testUnauthorized(function(cb) {
                request(groupsEndpoint, cb);
            });
        });

        describe('get /:key', function () {
            testUnauthorized(function(cb) {
                var testGroup = testGroups[0];
                request(groupsEndpoint + '/' + testGroup.key, cb);
            });
        });

        describe('post', function() {
           testUnauthorized(function(cb) {
               request.post(groupsEndpoint, cb);
           });
        });

        describe('put /:key', function() {
            testUnauthorized(function(cb) {
                var testGroup = testGroups[0];
                request.put(groupsEndpoint + '/' + testGroup.key, cb);
            });
        });
{'fraction_non_alphanumeric': 0.14233294708381614, 'fraction_numerical': 0.003862495171881035, 'mean_word_length': 1.607754279959718, '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': '4411374', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1342, 'n_words': 282}