123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- var App = require('app');
- require('mappers/alert_groups_mapper');
- var testHelpers = require('test/helpers');
- describe('App.alertGroupsMapper', function () {
- describe('#map', function () {
- var json = {
- items: [
- {
- "AlertGroup" : {
- "default" : true,
- "definitions" : [
- {
- "id" : 8,
- "source_type" : "PORT"
- },
- {
- "id" : 9,
- "source_type" : "AGGREGATE"
- }
- ],
- "id" : 3,
- "name" : "ZOOKEEPER",
- "targets": [{id: 1}, {id: 2}]
- }
- },
- {
- "AlertGroup" : {
- "default" : true,
- "definitions" : [
- {
- "id" : 1,
- "source_type" : "METRIC"
- },
- {
- "id" : 2,
- "source_type" : "WEB"
- },
- {
- "id" : 3,
- "source_type" : "WEB"
- },
- {
- "id" : 4,
- "source_type" : "AGGREGATE"
- },
- {
- "id" : 5,
- "source_type" : "METRIC"
- },
- {
- "id" : 6,
- "source_type" : "SCRIPT"
- },
- {
- "id" : 7,
- "source_type" : "WEB"
- }
- ],
- "id" : 2,
- "name" : "YARN",
- "targets": [{id: 2}, {id: 3}]
- }
- }
- ]
- };
- beforeEach(function () {
- sinon.stub(App.store, 'commit', Em.K);
- sinon.stub(App.store, 'loadMany', function (type, content) {
- type.content = content;
- });
- App.alertGroupsMapper.set('model', {});
- App.cache['previousAlertGroupsMap'] = {};
- });
- afterEach(function () {
- App.store.commit.restore();
- App.store.loadMany.restore();
- App.alertGroupsMapper.set('model', App.AlertGroup);
- App.cache['previousAlertGroupsMap'] = {};
- });
- it('should parse alert groups', function() {
- var expected = [
- {
- id: 3,
- name: 'ZOOKEEPER',
- default: true,
- port_alert_definitions: [8],
- metrics_alert_definitions: [],
- web_alert_definitions: [],
- aggregate_alert_definitions: [9],
- script_alert_definitions: [],
- targets: [1, 2]
- },
- {
- id: 2,
- name: 'YARN',
- default: true,
- port_alert_definitions: [],
- metrics_alert_definitions: [1, 5],
- web_alert_definitions: [2, 3, 7],
- aggregate_alert_definitions: [4],
- script_alert_definitions: [6],
- targets: [2, 3]
- }
- ];
- App.alertGroupsMapper.map(json);
- var mapped = App.alertGroupsMapper.get('model.content');
- testHelpers.nestedExpect(expected, mapped);
- });
- it('should set App.cache.previousAlertGroupsMap', function () {
- var expected = {
- 8: [3],
- 9: [3],
- 1: [2],
- 2: [2],
- 3: [2],
- 4: [2],
- 5: [2],
- 6: [2],
- 7: [2]
- };
- App.alertGroupsMapper.map(json);
- expect(App.cache['previousAlertGroupsMap']).to.eql(expected);
- });
- describe('should delete not existing groups', function () {
- var groups = [
- {id: 1},
- {id: 2},
- {id: 3},
- {id: 4}
- ];
- beforeEach(function () {
- sinon.stub(App.AlertGroup, 'find', function() {
- if (arguments.length) {
- return groups.findProperty('id', arguments[0]);
- }
- return groups;
- });
- sinon.stub(App.alertGroupsMapper, 'deleteRecord', Em.K);
- });
- afterEach(function () {
- App.AlertGroup.find.restore();
- App.alertGroupsMapper.deleteRecord.restore();
- });
- it('should call deleteRecord with not existing groups', function () {
- App.alertGroupsMapper.map(json);
- expect(App.alertGroupsMapper.deleteRecord.calledTwice).to.be.true;
- // first call
- expect(App.alertGroupsMapper.deleteRecord.args[0][0].id).to.equal(1);
- // second call
- expect(App.alertGroupsMapper.deleteRecord.args[1][0].id).to.equal(4);
- });
- });
- });
- });
|