-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix
options
parameter in metadata query method
- Loading branch information
1 parent
153fa16
commit 0b85218
Showing
3 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use strict'; | ||
|
||
const {getAppClient} = require('../context'); | ||
const {createBoxTestFolder} = require('../objects/box-test-folder'); | ||
const {createBoxTestFile} = require('../objects/box-test-file'); | ||
const utils = require('../lib/utils'); | ||
const path = require('path'); | ||
const context = {}; | ||
|
||
beforeAll(async() => { | ||
context.appClient = await getAppClient(); | ||
let folder = await createBoxTestFolder(context.appClient); | ||
context.folder = folder; | ||
}); | ||
|
||
afterAll(async() => { | ||
await context.folder.dispose(); | ||
context.folder = null; | ||
}); | ||
|
||
test('test matadata search', async() => { | ||
const templateKey = `template_${utils.randomName()}`; | ||
const fields = [ | ||
{ | ||
type: 'float', | ||
key: 'testFloatValue', | ||
displayName: 'testFloatValue', | ||
}, | ||
]; | ||
|
||
const metadataTemplate = await context.appClient.metadata.createTemplate(templateKey, fields, { | ||
scope: 'enterprise', | ||
templateKey: templateKey, | ||
}); | ||
|
||
expect(metadataTemplate.id) | ||
.toBeDefined(); | ||
expect(metadataTemplate.templateKey) | ||
.toBe(templateKey); | ||
expect(metadataTemplate.displayName) | ||
.toBe(templateKey); | ||
|
||
const file = await createBoxTestFile(context.appClient, path.join(__dirname, '../resources/blank.pdf'), 'blank_sign_1.pdf', context.folder.id); | ||
try { | ||
const metadata = await context.appClient.files.addMetadata(file.id, 'enterprise', templateKey, {testFloatValue: 150}); | ||
expect(metadata.$template) | ||
.toBe(templateKey); | ||
expect(metadata.testFloatValue) | ||
.toBe(150); | ||
|
||
const searchForm = `${metadataTemplate.scope}.${metadataTemplate.templateKey}`; | ||
const ancestorFolderId = '0'; | ||
const queryOptions = { | ||
query: 'testFloatValue >= :arg', | ||
query_params: {arg: '100'}, | ||
limit: 1, | ||
order_by: [ | ||
{ | ||
'field_key': 'testFloatValue', | ||
'direction': 'asc', | ||
}, | ||
], | ||
}; | ||
const searchResults = await context.appClient.metadata.query(searchForm, ancestorFolderId, queryOptions); | ||
expect(searchResults.entries.length) | ||
.toBe(1); | ||
expect(searchResults.entries[0].name) | ||
.toBe(file.name); | ||
|
||
await context.appClient.metadata.deleteTemplate('enterprise', metadataTemplate.templateKey); | ||
} | ||
finally { | ||
await file.dispose(); | ||
} | ||
}, 120000); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters