Skip to content

Commit

Permalink
Adjust parsing report_format_ids in alert model
Browse files Browse the repository at this point in the history
  • Loading branch information
swaterkamp committed Dec 20, 2018
1 parent acf94cd commit 2af51f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 11 additions & 4 deletions gsa/src/gmp/models/__tests__/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('Alert Model tests', () => {
expect(alert.method).toEqual({
data: {
bar: {value: '42'},
report_formats: [],
},
type: 'foo',
});
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('Alert Model tests', () => {
},
value: '42',
},
report_formats: [],
},
type: 'foo',
});
Expand Down Expand Up @@ -125,17 +127,22 @@ describe('Alert Model tests', () => {

test('should parse report format ids', () => {
const elem = {
report_format_ids: '123,456,789',
method: {
data: {
__text: '123, 456, 789',
name: 'report_formats',
},
},
};
const alert = new Alert(elem);

expect(alert.reportFormatIds).toEqual(['123', '456', '789']);
expect(alert.method.data.report_formats).toEqual(['123', '456', '789']);
});

test('should return empty array of no report format ids are given', () => {
test('should return empty array if no report format ids are given', () => {
const alert = new Alert({});

expect(alert.reportFormatIds).toEqual([]);
expect(alert.method.data.report_formats).toEqual([]);
});

test('isActive() should return correct true/false', () => {
Expand Down
9 changes: 6 additions & 3 deletions gsa/src/gmp/models/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ class Alert extends Model {
ret.tasks = [];
}

if (isDefined(elem.report_format_ids)) {
ret.reportFormatIds = elem.report_format_ids.split(',');
const methDatRepForm = ret.method.data.report_formats;

if (isDefined(methDatRepForm) && isDefined(methDatRepForm.value)) {
const methDatRepFormSplit = methDatRepForm.value.split(',');
ret.method.data.report_formats = methDatRepFormSplit.map(rf => rf.trim());
}
else {
ret.reportFormatIds = [];
ret.method.data.report_formats = [];
}

ret.active = parseYesNo(elem.active);
Expand Down

0 comments on commit 2af51f3

Please sign in to comment.