search接口实现修改

Signed-off-by: anyueling <anyueling@huawei.com>
This commit is contained in:
anyueling 2023-09-05 11:28:41 +08:00
parent beda9a9d04
commit 47490bb273
3 changed files with 85 additions and 11 deletions

View File

@ -215,9 +215,9 @@ struct Filter {
std::string bundle;
int64_t before;
int64_t after;
State state;
Action action;
Mode mode;
State state = State::ANY;
Action action = Action::ANY;
Mode mode = Mode::ANY;
};
enum DownloadErrorCode {

View File

@ -391,11 +391,18 @@ bool JsTask::ParseTouch(napi_env env, size_t argc, napi_value *argv, std::shared
bool JsTask::ParseSearch(napi_env env, size_t argc, napi_value *argv, Filter &filter)
{
using namespace std::chrono;
filter.bundle = "*";
filter.before = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
filter.after = filter.before - MILLISECONDS_IN_ONE_DAY;
if (argc < 1) {
REQUEST_HILOGE("Wrong number of arguments");
return false;
return true;
}
if (NapiUtils::GetValueType(env, argv[0]) != napi_object) {
napi_valuetype valueType = NapiUtils::GetValueType(env, argv[0]);
if (valueType == napi_null || valueType == napi_undefined) {
return true;
}
if (valueType != napi_object) {
REQUEST_HILOGE("The parameter is not of object type");
return false;
}

View File

@ -457,12 +457,16 @@ export default function requestQueryTest() {
* @tc.require:
*/
it('testSearchTask001', 0, async function (done) {
try {
await request.agent.search();
} catch (err) {
expect(err.code).assertEqual(401);
done();
let conf = {
action: request.agent.Action.DOWNLOAD,
url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk',
}
let task = await request.agent.create(context, conf);
request.agent.search(async (err, tids) => {
expect(tids.length > 0).assertTrue();
await request.agent.remove(task.tid);
done();
})
})
/**
@ -792,6 +796,69 @@ export default function requestQueryTest() {
})
})
/**
* @tc.name: testSearchTask016
* @tc.desc: Test search task for filter is empty
* @tc.type: FUNC
* @tc.require:
*/
it('testSearchTask016', 0, async function (done) {
let conf = {
action: request.agent.Action.DOWNLOAD,
url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk',
}
let task = await request.agent.create(context, conf);
request.agent.search().then(async (tids) => {
expect(tids.length > 0).assertTrue();
await request.agent.remove(task.tid);
done();
}).catch((err) => {
expect(false).assertTrue();
done();
})
})
/**
* @tc.name: testSearchTask017
* @tc.desc: Test search task for filter is undefined
* @tc.type: FUNC
* @tc.require:
*/
it('testSearchTask017', 0, async function (done) {
let conf = {
action: request.agent.Action.DOWNLOAD,
url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk',
}
let task = await request.agent.create(context, conf);
request.agent.search(undefined).then(async (tids) => {
expect(tids.length > 0).assertTrue();
await request.agent.remove(task.tid);
done();
}).catch((err) => {
expect(false).assertTrue();
done();
})
})
/**
* @tc.name: testSearchTask018
* @tc.desc: Test search task for filter is null
* @tc.type: FUNC
* @tc.require:
*/
it('testSearchTask018', 0, async function (done) {
let conf = {
action: request.agent.Action.DOWNLOAD,
url: 'https://gitee.com/chenzhixue/downloadTest/releases/download/v1.0/test.apk',
}
let task = await request.agent.create(context, conf);
request.agent.search(null, async (err, tids) => {
expect(tids.length > 0).assertTrue();
await request.agent.remove(task.tid);
done();
})
})
/**
* @tc.name: testQueryTask001
* @tc.desc: Test query task for tid is "123"