<commit_before>(function ($, _, Backbone, Strophe, jasmine, xmppMocker, PubSubStorage, PubSubItem, PubSubNode) {

    describe('PubSubItem/PubSubNode model/collection', function () {

        var connection, response, p, successHandler, errorHandler, json, entry,
            item, items;

        var Model = PubSubItem.extend({
            }),
            Collection = PubSubNode.extend({
                model: Model
            });

        beforeEach(function () {
            connection = xmppMocker.mockConnection();
            successHandler = jasmine.createSpy('successHandler');
            errorHandler = jasmine.createSpy('errorHandler');
            json = {title: 'An entry',
                            geolocation: {latitude: 10.23, longitude: 20.45},
                            published: '1974-06-05T09:13:00Z'},
            entry = $build('entry').t(JSON.stringify(json)).tree();

        });

        it('uses Backbone.xmppSync', function () {
            items = new Collection();
            expect(items.sync).toEqual(Backbone.xmppSync);
            item = new Model();
            expect(item.sync).toEqual(Backbone.xmppSync);
        });

        it('contructs the node attribute when initialized with an id', function () {
            items = new Collection([], {id: 'anode', connection: connection});
            expect(items.node.id).toEqual('anode');
            expect(items.node.connection).toEqual(connection);
        });
        
        it('pubsub node can be changed after initialization', function () {
            items = new Collection([], {id: 'anode', connection: connection});
            expect(items.node.id).toEqual('anode');
            expect(items.node.connection).toEqual(connection);
            items.setNode('anode2', connection);
            expect(items.node.id).toEqual('anode2');
        });

        it('adds an item to index 0 of the collection upon receiving an PEP notification on a non-existing item and fires the "add" event.', function () {
            items = new PubSubNode([{id: 'xxx', title: 'Old entry'}], {id: 'anode', connection: connection});
            message = $msg({from: connection.PubSub.service, to: connection.jid})
                .c('event', {xmlns: Strophe.NS.PUBSUB_EVENT})
                .c('items', {node: 'anode'})
                .c('item', {id: 'item_id'})
                .cnode(entry);
            items.on('add', successHandler);
            xmppMocker.receive(connection, message);
            expect(successHandler).toHaveBeenCalled();
            item = items.get('item_id');
            expect(item).toBeDefined();
            expect(item.get('title')).toEqual('An entry');
            expect(item.get('published')).toEqual('1974-06-05T09:13:00Z');
            expect(item.get('geolocation')).toEqual({latitude: 10.23, longitude: 20.45});
            // Make sure it's first on the list
            expect(items.indexOf(item)).toEqual(0);
        });

        it('adds an item to index 0 of the collection upon receiving an PEP notification on a non-existing item without a payload and fires the "add" event.', function () {
            spyOn(connection.PubSub, 'items').andCallFake(function () {
                var d = $.Deferred(),<commit_msg>verbal consistency ;)<commit_after>(function ($, _, Backbone, Strophe, jasmine, xmppMocker, PubSubStorage, PubSubItem, PubSubNode) {

    describe('PubSubItem/PubSubNode model/collection', function () {

        var connection, response, p, successHandler, errorHandler, json, entry,
            item, items;

        var Model = PubSubItem.extend({
            }),
            Collection = PubSubNode.extend({
                model: Model
            });

        beforeEach(function () {
            connection = xmppMocker.mockConnection();
            successHandler = jasmine.createSpy('successHandler');
            errorHandler = jasmine.createSpy('errorHandler');
            json = {title: 'An entry',
                            geolocation: {latitude: 10.23, longitude: 20.45},
                            published: '1974-06-05T09:13:00Z'},
            entry = $build('entry').t(JSON.stringify(json)).tree();

        });

        it('uses Backbone.xmppSync', function () {
            items = new Collection();
            expect(items.sync).toEqual(Backbone.xmppSync);
            item = new Model();
            expect(item.sync).toEqual(Backbone.xmppSync);
        });

        it('contructs the node attribute when initialized with an id', function () {
            items = new Collection([], {id: 'anode', connection: connection});
            expect(items.node.id).toEqual('anode');
            expect(items.node.connection).toEqual(connection);
        });

        it('can change the pubsub node after initialization', function () {
            items = new Collection([], {id: 'anode', connection: connection});
            expect(items.node.id).toEqual('anode');
            expect(items.node.connection).toEqual(connection);
            items.setNode('anode2', connection);
            expect(items.node.id).toEqual('anode2');
        });

        it('adds an item to index 0 of the collection upon receiving an PEP notification on a non-existing item and fires the "add" event.', function () {
            items = new PubSubNode([{id: 'xxx', title: 'Old entry'}], {id: 'anode', connection: connection});
            message = $msg({from: connection.PubSub.service, to: connection.jid})
                .c('event', {xmlns: Strophe.NS.PUBSUB_EVENT})
                .c('items', {node: 'anode'})
                .c('item', {id: 'item_id'})
                .cnode(entry);
            items.on('add', successHandler);
            xmppMocker.receive(connection, message);
            expect(successHandler).toHaveBeenCalled();
            item = items.get('item_id');
            expect(item).toBeDefined();
            expect(item.get('title')).toEqual('An entry');
            expect(item.get('published')).toEqual('1974-06-05T09:13:00Z');
            expect(item.get('geolocation')).toEqual({latitude: 10.23, longitude: 20.45});
            // Make sure it's first on the list
            expect(items.indexOf(item)).toEqual(0);
        });

        it('adds an item to index 0 of the collection upon receiving an PEP notification on a non-existing item without a payload and fires the "add" event.', function () {
            spyOn(connection.PubSub, 'items').andCallFake(function () {
                var d = $.Deferred(),
{'fraction_non_alphanumeric': 0.14083204930662557, 'fraction_numerical': 0.01510015408320493, 'mean_word_length': 2.2471235617808905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4725021', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1739, 'n_words': 407}