|
| 1 | +import { firstNonEmptyPropertyValue } from '../../../src/utils/DatasetUtils'; |
| 2 | + |
| 3 | +describe('firstNonEmptyPropertyValue', () => { |
| 4 | + it('ensure no errors when no study properties', async () => { |
| 5 | + const dataset = { id: 1, study: { id: 2 }}; |
| 6 | + const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]); |
| 7 | + expect(result).to.be.empty; |
| 8 | + }); |
| 9 | + it('ensure no errors when no dataset properties', async () => { |
| 10 | + const dataset = { id: 1 }; |
| 11 | + const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]); |
| 12 | + expect(result).to.be.empty; |
| 13 | + }); |
| 14 | + it('ensure no errors when incorrect properties', async () => { |
| 15 | + const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' } ]}}; |
| 16 | + const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]); |
| 17 | + expect(result).to.be.empty; |
| 18 | + }); |
| 19 | + it('ensure no errors when empty study property values', async () => { |
| 20 | + const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello' } ]}}; |
| 21 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]); |
| 22 | + expect(result).to.be.empty; |
| 23 | + }); |
| 24 | + it('ensure no errors when empty dataset property values', async () => { |
| 25 | + const dataset = { id: 1, properties: [ { propertyName: 'hello' } ]}; |
| 26 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]); |
| 27 | + expect(result).to.be.empty; |
| 28 | + }); |
| 29 | + it('extract hello property from study', async () => { |
| 30 | + const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' } ]}}; |
| 31 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]); |
| 32 | + expect(result).to.equal('goodbye'); |
| 33 | + }); |
| 34 | + it('extract hello property from dataset', async () => { |
| 35 | + const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ]}; |
| 36 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]); |
| 37 | + expect(result).to.equal('goodbye'); |
| 38 | + }); |
| 39 | + it('prioritize study property over dataset property', async () => { |
| 40 | + const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ], study: { id: 2, properties: [ { key: 'hello', value: 'world' } ]}}; |
| 41 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]); |
| 42 | + expect(result).to.equal('world'); |
| 43 | + }); |
| 44 | + it('extract first available property from study', async () => { |
| 45 | + const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' }, { key: 'world', value: 'hello' } ]}}; |
| 46 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello', 'world' ]); |
| 47 | + expect(result).to.equal('goodbye'); |
| 48 | + }); |
| 49 | + it('extract first available property from dataset', async () => { |
| 50 | + const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' }, { propertyName: 'world', propertyValue: 'hello' } ]}; |
| 51 | + const result = firstNonEmptyPropertyValue(dataset, [ 'hello', 'world' ]); |
| 52 | + expect(result).to.equal('goodbye'); |
| 53 | + }); |
| 54 | + it('extract mix of properties from study and dataset', async () => { |
| 55 | + const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ], study: { id: 2, properties: [ { key: 'world', value: 'hello' } ]}}; |
| 56 | + const result = firstNonEmptyPropertyValue(dataset, [ 'world', 'hello' ]); |
| 57 | + expect(result).to.equal('hello'); |
| 58 | + }); |
| 59 | +}); |
0 commit comments