|
| 1 | +import { locationAssign } from './helper.js' |
| 2 | + |
| 3 | +describe('locationAssign', () => { |
| 4 | + it('should create a file name based on the params', () => { |
| 5 | + const url = |
| 6 | + 'https://debug.dhis2.org/dev/api/tracker/trackedEntities.json?ouMode=CAPTURE&format=json&includeDeleted=false&dataElementIdScheme=UID&eventIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=trackedEntities.json&paging=false&totalPages=false&program=lxAQ7Zs9VYR' |
| 7 | + const link = locationAssign(url) |
| 8 | + expect(link.download).toEqual('trackedEntities.json') |
| 9 | + }) |
| 10 | + it('should create url with orgUnits', () => { |
| 11 | + const url = |
| 12 | + 'https://debug.dhis2.org/dev/api/tracker/trackedEntities.json?ouMode=SELECTED&includeDeleted=false&dataElementIdScheme=UID&eventIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=trackedEntities.json&paging=false&totalPages=false&orgUnits=O6uvpzGd5pu,fdc6uOvgoji&program=kla3mAPgvCH' |
| 13 | + const link = locationAssign(url) |
| 14 | + expect(link.download).toEqual('trackedEntities.json') |
| 15 | + }) |
| 16 | + it('should create url with tracked entities', () => { |
| 17 | + const url = |
| 18 | + 'https://debug.dhis2.org/dev/api/tracker/trackedEntities.json?ouMode=SELECTED&includeDeleted=false&dataElementIdScheme=UID&eventIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=trackedEntities.json&paging=false&totalPages=false&orgUnits=ImspTQPwCqd&trackedEntityType=bVkFYAvoUCP' |
| 19 | + const link = locationAssign(url) |
| 20 | + expect(link.download).toEqual('trackedEntities.json') |
| 21 | + }) |
| 22 | + it('should create url with CSV', () => { |
| 23 | + const url = |
| 24 | + 'https://debug.dhis2.org/dev/api/tracker/trackedEntities.csv?ouMode=SELECTED&includeDeleted=false&dataElementIdScheme=UID&eventIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=trackedEntities.csv&paging=false&totalPages=false&orgUnits=ImspTQPwCqd&program=lxAQ7Zs9VYR' |
| 25 | + const link = locationAssign(url) |
| 26 | + expect(link.download).toEqual('trackedEntities.csv') |
| 27 | + }) |
| 28 | + |
| 29 | + it('should create url with events zip', () => { |
| 30 | + const url = |
| 31 | + 'https://debug.dhis2.org/dev/api/tracker/events.json.zip?links=false&paging=false&totalPages=false&orgUnit=fwH9ipvXde9&program=VBqh0ynB2wv&includeDeleted=false&dataElementIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=events.json.zip&occurredAfter=2023-12-12&occurredBefore=2024-03-12&ouMode=CHILDREN&format=json' |
| 32 | + const link = locationAssign(url) |
| 33 | + expect(link.download).toEqual('events.json.zip') |
| 34 | + }) |
| 35 | + |
| 36 | + it('should create url with events gzip', () => { |
| 37 | + const url = |
| 38 | + 'https://debug.dhis2.org/dev/api/tracker/events.json.gz?links=false&paging=false&totalPages=false&orgUnit=ImspTQPwCqd&program=lxAQ7Zs9VYR&includeDeleted=false&dataElementIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=events.json.gz&occurredAfter=2023-12-12&occurredBefore=2024-03-12&ouMode=SELECTED&format=json' |
| 39 | + const link = locationAssign(url) |
| 40 | + expect(link.download).toEqual('events.json.gz') |
| 41 | + }) |
| 42 | + it('should work with relative URLs when bundled in DHIS2', () => { |
| 43 | + Object.defineProperty(global.document, 'baseURI', { |
| 44 | + value: 'http://localhost:8080/dhis-web-import-export/index.html#/export/tei', |
| 45 | + }) |
| 46 | + const url = |
| 47 | + '../api/tracker/trackedEntities.json?ouMode=SELECTED&includeDeleted=false&dataElementIdScheme=UID&eventIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=trackedEntities.json&paging=false&totalPages=false&orgUnits=ImspTQPwCqd&program=lxAQ7Zs9VYR' |
| 48 | + const link = locationAssign(url) |
| 49 | + expect(link.download).toEqual('trackedEntities.json') |
| 50 | + }) |
| 51 | + it('should work with relative URLs when bundled in DHIS2 for zip', () => { |
| 52 | + Object.defineProperty(global.document, 'baseURI', { |
| 53 | + value: 'http://localhost:8080/dhis-web-import-export/index.html#/export/tei', |
| 54 | + }) |
| 55 | + const url = |
| 56 | + '../api/tracker/events.json.zip?links=false&paging=false&totalPages=false&orgUnit=ImspTQPwCqd&program=lxAQ7Zs9VYR&includeDeleted=false&dataElementIdScheme=UID&orgUnitIdScheme=UID&idScheme=UID&attachment=events.json.zip&occurredAfter=2023-12-12&occurredBefore=2024-03-12&ouMode=SELECTED&format=json' |
| 57 | + const link = locationAssign(url) |
| 58 | + expect(link.download).toEqual('events.json.zip') |
| 59 | + }) |
| 60 | +}) |
0 commit comments