<commit_before>var _ = require('lodash'),
    expect = require('chai').expect,
    fixtures = require('../fixtures'),
    sdk = require('../../lib/index.js'),
    Item = sdk.Item,
    ItemGroup = sdk.ItemGroup,
    Collection = sdk.Collection;

describe('ItemGroup', function () {
    describe('constructor', function () {
        it('should handle all properties', function () {
            var itemGroupDefinition = {
                    auth: {
                        type: 'basic',
                        basic: [{
                            key: 'username',
                            type: 'string',
                            value: 'postman'
                        }, {
                            key: 'password',
                            type: 'string',
                            value: 'password'
                        }]
                    },
                    event: [{
                        listen: 'test',
                        script: {
                            id: 'my-script-1',
                            type: 'text/javascript',
                            exec: ['console.log("This doesn\'t matter");']
                        }
                    }]
                },
                itemGroup = new ItemGroup(itemGroupDefinition);

            expect(itemGroup).to.deep.include({
                events: new sdk.EventList({}, itemGroupDefinition.event),
                auth: new sdk.RequestAuth(itemGroupDefinition.auth)
            });
            expect(itemGroup).to.have.property('items');
        });

        it('should not create auth if auth is falsy', function () {
            var itemGroupDefinition = {
                    auth: null
                },
                itemGroup = new ItemGroup(itemGroupDefinition);

            expect(itemGroup).to.not.have.property('auth');
            expect(itemGroup.toJSON()).to.not.have.property('auth');
        });
    });
    it('must be able to iterate over all subfolders', function () {
        var rawCollection = fixtures.collectionV2,
            collection = new Collection(rawCollection),
            groups = [];

        collection.forEachItemGroup(function (group) {
            groups.push(group);
        });
        expect(groups.length).to.equal(4);
    });

    it('should correctly handle incoming items/item groups and/or plain objects', function () {
        var plain = ItemGroup._createNewGroupOrItem({
                request: {
                    url: 'https://postman-echo.com/get',
                    method: 'GET'
                }
            }),
            item = ItemGroup._createNewGroupOrItem(new sdk.Item({
                request: {
                    url: 'https://postman-echo.com/get',
                    method: 'GET'
                }
            })),
            group = ItemGroup._createNewGroupOrItem(new sdk.ItemGroup({ name: 'Blank folder' }));

        expect(plain).to.be.ok;
        expect(plain.events).to.be.ok;
        expect(plain.responses).to.be.ok;
        expect(plain.request).to.have.property('method', 'GET');
        expect(plain.request.url).to.deep.include({
            path: ['get'],
            host: ['postman-echo', 'com']
        });

        expect(item).to.be.ok;
        expect(item.events).to.be.ok;
        expect(item.responses).to.be.ok;
        expect(item.request).to.have.property('method', 'GET');
        expect(item.request.url).to.deep.include({
            path: ['get'],
            host: ['postman-echo', 'com']
        });

        expect(_.omit(group.toJSON(), 'id')).to.eql({ name: 'Blank folder', item: [], event: [] });
    });

    describe('sanity', function () {
        var rawItemGroup = fixtures.collectionV2,
            itemGroup = new ItemGroup(rawItemGroup);

        it('initializes successfully', function () {
            expect(itemGroup).to.be.ok;
        });

        describe('has property', function () {
            it('id', function () {
                expect(itemGroup).to.have.property('id', rawItemGroup.info.id);
            });

            it('item', function () {
                expect(itemGroup).to.have.property('items').that.is.an('object');
                expect(itemGroup.items.all()).to.be.an('array').that.has.lengthOf(3);
            });

            it('name', function () {
                expect(itemGroup).to.have.property('name', rawItemGroup.info.name);
            });
            it('events', function () {
                expect(itemGroup).to.have.property('events');
                expect(itemGroup.events.all()).to.be.an('array').that.has.lengthOf(2);
            });
        });

        describe('has function', function () {
            it('forEachItem', function () {
                expect(itemGroup.forEachItem).to.be.ok;
                expect(itemGroup.forEachItem).to.be.a('function');
            });
        });
    });

    describe('.parent checks', function () {
        var collection = new Collection(fixtures.nestedCollectionV2);

        it('should work correctly for nested collections', function () {
            collection.forEachItemGroup(function (group) {
                var groupIds = [],
                    parentIds = [],
                    parent = group.parent();

                while (parent) {
                    parentIds.push(parent.id);
                    expect(parent).to.include.keys(['description', 'id', 'name', 'items', 'events']);
                    parent = parent.parent();
                }

                collection.forEachItemGroup(function (item) {
                    groupIds.unshift(item.id);
                });

                // The top most parent is always the collection, check that here
                expect(parentIds.pop()).to.equal(collection.id);

                // Check that the parents returned by .parent are in the same order as those of the itemGroup list
                _.forEach(parentIds, function (id, index) {
                    expect(id).to.equal(groupIds[index]);
                });
            });
        });

        it('must work correctly for a nested itemGroup', function () {
            var f2 = collection.items.members[1],
                f3 = f2.items.members[0],
                parent = f3.parent();

            expect(parent.name).to.equal(f2.name);
        });

        it('must work correctly for a first level itemGroup', function () {
            var f1 = collection.items.members[0],
                parent = f1.parent();

            expect(parent.name).to.equal(collection.name);
        });
    });

    describe('.forEachItem', function () {
        it('should correctly iterate over a nested list of items and item groups', function () {
            var result = [],
                itemGroup = new ItemGroup({
                    id: 'F0',
                    name: 'F0-name',
                    item: [{
                        id: 'R1',
                        name: 'R1-name',
                        request: 'postman-echo.com'
                    }, {
                        id: 'F2',
                        name: 'F2-name',
                        item: [{
                            id: 'R2',
                            name: 'R2-name',
                            request: 'postman-echo.com'
                        }, {
                            id: 'R3',
                            name: 'R3-name',
                            request: 'postman-echo.com'
                        }, {
                            id: 'F3',
                            name: 'F3-name',<commit_msg>Update must to should in item-group test<commit_after>var _ = require('lodash'),
    expect = require('chai').expect,
    fixtures = require('../fixtures'),
    sdk = require('../../lib/index.js'),
    Item = sdk.Item,
    ItemGroup = sdk.ItemGroup,
    Collection = sdk.Collection;

describe('ItemGroup', function () {
    describe('constructor', function () {
        it('should handle all properties', function () {
            var itemGroupDefinition = {
                    auth: {
                        type: 'basic',
                        basic: [{
                            key: 'username',
                            type: 'string',
                            value: 'postman'
                        }, {
                            key: 'password',
                            type: 'string',
                            value: 'password'
                        }]
                    },
                    event: [{
                        listen: 'test',
                        script: {
                            id: 'my-script-1',
                            type: 'text/javascript',
                            exec: ['console.log("This doesn\'t matter");']
                        }
                    }]
                },
                itemGroup = new ItemGroup(itemGroupDefinition);

            expect(itemGroup).to.deep.include({
                events: new sdk.EventList({}, itemGroupDefinition.event),
                auth: new sdk.RequestAuth(itemGroupDefinition.auth)
            });
            expect(itemGroup).to.have.property('items');
        });

        it('should not create auth if auth is falsy', function () {
            var itemGroupDefinition = {
                    auth: null
                },
                itemGroup = new ItemGroup(itemGroupDefinition);

            expect(itemGroup).to.not.have.property('auth');
            expect(itemGroup.toJSON()).to.not.have.property('auth');
        });
    });
    it('should be able to iterate over all subfolders', function () {
        var rawCollection = fixtures.collectionV2,
            collection = new Collection(rawCollection),
            groups = [];

        collection.forEachItemGroup(function (group) {
            groups.push(group);
        });
        expect(groups.length).to.equal(4);
    });

    it('should correctly handle incoming items/item groups and/or plain objects', function () {
        var plain = ItemGroup._createNewGroupOrItem({
                request: {
                    url: 'https://postman-echo.com/get',
                    method: 'GET'
                }
            }),
            item = ItemGroup._createNewGroupOrItem(new sdk.Item({
                request: {
                    url: 'https://postman-echo.com/get',
                    method: 'GET'
                }
            })),
            group = ItemGroup._createNewGroupOrItem(new sdk.ItemGroup({ name: 'Blank folder' }));

        expect(plain).to.be.ok;
        expect(plain.events).to.be.ok;
        expect(plain.responses).to.be.ok;
        expect(plain.request).to.have.property('method', 'GET');
        expect(plain.request.url).to.deep.include({
            path: ['get'],
            host: ['postman-echo', 'com']
        });

        expect(item).to.be.ok;
        expect(item.events).to.be.ok;
        expect(item.responses).to.be.ok;
        expect(item.request).to.have.property('method', 'GET');
        expect(item.request.url).to.deep.include({
            path: ['get'],
            host: ['postman-echo', 'com']
        });

        expect(_.omit(group.toJSON(), 'id')).to.eql({ name: 'Blank folder', item: [], event: [] });
    });

    describe('sanity', function () {
        var rawItemGroup = fixtures.collectionV2,
            itemGroup = new ItemGroup(rawItemGroup);

        it('initializes successfully', function () {
            expect(itemGroup).to.be.ok;
        });

        describe('has property', function () {
            it('id', function () {
                expect(itemGroup).to.have.property('id', rawItemGroup.info.id);
            });

            it('item', function () {
                expect(itemGroup).to.have.property('items').that.is.an('object');
                expect(itemGroup.items.all()).to.be.an('array').that.has.lengthOf(3);
            });

            it('name', function () {
                expect(itemGroup).to.have.property('name', rawItemGroup.info.name);
            });
            it('events', function () {
                expect(itemGroup).to.have.property('events');
                expect(itemGroup.events.all()).to.be.an('array').that.has.lengthOf(2);
            });
        });

        describe('has function', function () {
            it('forEachItem', function () {
                expect(itemGroup.forEachItem).to.be.ok;
                expect(itemGroup.forEachItem).to.be.a('function');
            });
        });
    });

    describe('.parent checks', function () {
        var collection = new Collection(fixtures.nestedCollectionV2);

        it('should work correctly for nested collections', function () {
            collection.forEachItemGroup(function (group) {
                var groupIds = [],
                    parentIds = [],
                    parent = group.parent();

                while (parent) {
                    parentIds.push(parent.id);
                    expect(parent).to.include.keys(['description', 'id', 'name', 'items', 'events']);
                    parent = parent.parent();
                }

                collection.forEachItemGroup(function (item) {
                    groupIds.unshift(item.id);
                });

                // The top most parent is always the collection, check that here
                expect(parentIds.pop()).to.equal(collection.id);

                // Check that the parents returned by .parent are in the same order as those of the itemGroup list
                _.forEach(parentIds, function (id, index) {
                    expect(id).to.equal(groupIds[index]);
                });
            });
        });

        it('should work correctly for a nested itemGroup', function () {
            var f2 = collection.items.members[1],
                f3 = f2.items.members[0],
                parent = f3.parent();

            expect(parent.name).to.equal(f2.name);
        });

        it('should work correctly for a first level itemGroup', function () {
            var f1 = collection.items.members[0],
                parent = f1.parent();

            expect(parent.name).to.equal(collection.name);
        });
    });

    describe('.forEachItem', function () {
        it('should correctly iterate over a nested list of items and item groups', function () {
            var result = [],
                itemGroup = new ItemGroup({
                    id: 'F0',
                    name: 'F0-name',
                    item: [{
                        id: 'R1',
                        name: 'R1-name',
                        request: 'postman-echo.com'
                    }, {
                        id: 'F2',
                        name: 'F2-name',
                        item: [{
                            id: 'R2',
                            name: 'R2-name',
                            request: 'postman-echo.com'
                        }, {
                            id: 'R3',
                            name: 'R3-name',
                            request: 'postman-echo.com'
                        }, {
                            id: 'F3',
                            name: 'F3-name',
{'fraction_non_alphanumeric': 0.13450755326868527, 'fraction_numerical': 0.0038261099017085558, 'mean_word_length': 1.30325129140079, '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': '6174190', 'n_tokens_mistral': 3883, 'n_tokens_neox': 3660, 'n_words': 713}