Skip to content

Commit 278f096

Browse files
authored
Merge pull request #23 from tainguyenbui/feature/HASI-552_get_original_file_by_default
HASI-552 get original file by default
2 parents 65cf6b7 + 51d06a3 commit 278f096

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-dataverse",
3-
"version": "1.0.38",
3+
"version": "1.0.39",
44
"description": "A Dataverse module for JavaScript/TypeScript",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/dataverseClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export class DataverseClient {
5858
})
5959
}
6060

61-
public async getFile(fileId: string): Promise<AxiosResponse> {
62-
const url = `${this.host}/api/access/datafile/${fileId}`
61+
public async getFile(fileId: string, getOriginal = true): Promise<AxiosResponse> {
62+
const url = `${this.host}/api/access/datafile/${fileId}${getOriginal ? '?format=original' : ''}`
6363
return this.getRequest(url, {
6464
headers: this.getHeaders(),
6565
responseType: 'arraybuffer'

test/dataverseClient.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,34 @@ describe('DataverseClient', () => {
434434
await client.getFile(fileId)
435435

436436
assert.calledOnce(axiosGetStub)
437-
assert.calledWithExactly(axiosGetStub, `${host}/api/access/datafile/${fileId}`, {
437+
assert.calledWithExactly(axiosGetStub, `${host}/api/access/datafile/${fileId}?format=original`, {
438438
headers: { 'X-Dataverse-key': apiToken },
439439
responseType: 'arraybuffer'
440440
})
441441
})
442442

443+
describe('get ingested file', () => {
444+
it('should call axios with expected url', async () => {
445+
const fileId: string = random.number().toString()
446+
447+
await client.getFile(fileId, false)
448+
449+
assert.calledOnce(axiosGetStub)
450+
assert.calledWithExactly(axiosGetStub, `${host}/api/access/datafile/${fileId}`, {
451+
headers: { 'X-Dataverse-key': apiToken },
452+
responseType: 'arraybuffer'
453+
})
454+
})
455+
})
456+
443457
it('should call axios with expected headers when no apiToken provided', async () => {
444458
client = new DataverseClient(host)
445459
const fileId: string = random.number().toString()
446460

447461
await client.getFile(fileId)
448462

449463
assert.calledOnce(axiosGetStub)
450-
assert.calledWithExactly(axiosGetStub, `${host}/api/access/datafile/${fileId}`, {
464+
assert.calledWithExactly(axiosGetStub, `${host}/api/access/datafile/${fileId}?format=original`, {
451465
headers: { 'X-Dataverse-key': '' },
452466
responseType: 'arraybuffer'
453467
})
@@ -461,7 +475,7 @@ describe('DataverseClient', () => {
461475
'test': randomValue
462476
}
463477
axiosGetStub
464-
.withArgs(`${host}/api/access/datafile/${fileId}`, {
478+
.withArgs(`${host}/api/access/datafile/${fileId}?format=original`, {
465479
headers: { 'X-Dataverse-key': apiToken },
466480
responseType: 'arraybuffer'
467481
})

0 commit comments

Comments
 (0)