<commit_before>'use strict';

const specHelper = require('../../support/specHelper'),
      Branch = specHelper.models.Branch,
      Group = specHelper.models.Group;

var uuid = require('node-uuid');
var branchService = require('../../../src/backend/services/branchService');

function tearDown() {
    return Group.truncate({cascade: true})
        .then(Branch.truncate({cascade: true}));
}

function seed() {
    let branchWithGroups;
    return Branch.create({id: 'aa3538ae-763d-49d9-ac23-2281ba2145e4', name: 'Branch name no groups'})
    .then(function() {
        return Branch.create({id: 'fd4f7e67-66fe-4f7a-86a6-f031cb3af174', name: 'Branch name groups'});
    })
    .then(function(branch) {
      branchWithGroups = branch;
      return Group.create({ id: uuid(), name: 'Waiting List', description: 'This is a description of the waiting list' });
    })
    .then(function(group) {
      return branchWithGroups.addGroup(group);
    })
  .then(function() {
      return Group.create({ id: uuid(), name: 'Waiting List2', description: 'This is a description of the waiting list2' });
  })
  .then(function(group) {
      return branchWithGroups.addGroup(group);
  });
}

describe('branchService', () => {

    describe('groupsInBranch', () => {

        it('should return the branches groups if it has some', (done) => {
            let branchWithGroupsId = 'fd4f7e67-66fe-4f7a-86a6-f031cb3af174';

            tearDown()
            .then(seed)
            .then(() => {
                branchService.groupsInBranch(branchWithGroupsId)
                    .then((result) => {
                        expect(result.length).toEqual(2);
                    }).then(done, done.fail);

            });
        });

        it('should return no groups if the branch has none', (done) => {
            let branchWithNoGroupsId = 'aa3538ae-763d-49d9-ac23-2281ba2145e4';

            tearDown()
            .then(seed)
            .then(() => {
                branchService.groupsInBranch(branchWithNoGroupsId)
                    .then((result) => {
                        expect(result).toEqual([]);
                    }).then(done, done.fail);
            });
        });

        describe('sad scenarios', () => {
            it('should handle an invalid branchId', (done) => {
                let invalidBranchId = 'invalidId';

                tearDown()
                .then(seed)
                .then(() => {
                    branchService.groupsInBranch(invalidBranchId)
                        .then(() => {
                            jasmine.fail('This should not have succeded');
                        })
                        .catch((error) => {
                            expect(error.message).toEqual('Error when looking up branch with id: invalidId');
                        }).then(done, done.fail);
                });
            });
        });
    });
});<commit_msg>Move seed to beforeEach and beautify<commit_after>'use strict';

const specHelper = require('../../support/specHelper'),
    Branch = specHelper.models.Branch,
    Group = specHelper.models.Group;

var uuid = require('node-uuid');
var branchService = require('../../../src/backend/services/branchService');

function seed() {
    let branchWithGroups;
    return Branch.create({
            id: 'aa3538ae-763d-49d9-ac23-2281ba2145e4',
            name: 'Branch name no groups'
        })
        .then(function() {
            return Branch.create({
                id: 'fd4f7e67-66fe-4f7a-86a6-f031cb3af174',
                name: 'Branch name groups'
            });
        })
        .then(function(branch) {
            branchWithGroups = branch;
            return Group.create({
                id: uuid(),
                name: 'Waiting List',
                description: 'This is a description of the waiting list'
            });
        })
        .then(function(group) {
            return branchWithGroups.addGroup(group);
        })
        .then(function() {
            return Group.create({
                id: uuid(),
                name: 'Waiting List2',
                description: 'This is a description of the waiting list2'
            });
        })
        .then(function(group) {
            return branchWithGroups.addGroup(group);
        });
}

describe('branchService', () => {

    beforeEach((done) => {
        seed().nodeify(done);

    });

    describe('groupsInBranch', () => {

        it('should return the branches groups if it has some', (done) => {
            let branchWithGroupsId = 'fd4f7e67-66fe-4f7a-86a6-f031cb3af174';
            branchService.groupsInBranch(branchWithGroupsId)
                .then((result) => {
                    expect(result.length).toEqual(2);
                }).then(done, done.fail);
        });

        it('should return no groups if the branch has none', (done) => {
            let branchWithNoGroupsId = 'aa3538ae-763d-49d9-ac23-2281ba2145e4';
            branchService.groupsInBranch(branchWithNoGroupsId)
                .then((result) => {
                    expect(result).toEqual([]);
                }).then(done, done.fail);
        });

        describe('sad scenarios', () => {
            it('should handle an invalid branchId', (done) => {
                let invalidBranchId = 'invalidId';
                branchService.groupsInBranch(invalidBranchId)
                    .then(() => {
                        jasmine.fail('This should not have succeded');
                    })
                    .catch((error) => {
                        expect(error.message).toEqual('Error when looking up branch with id: invalidId');
                    }).then(done, done.fail);
            });
        });
    });
});
{'fraction_non_alphanumeric': 0.13860693034651733, 'fraction_numerical': 0.028351417570878543, 'mean_word_length': 1.7305303392259914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1088126', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1566, 'n_words': 313}