зеркало из https://github.com/mozilla/gecko-dev.git
fix wbo record test, expand to use record manager as well
This commit is contained in:
Родитель
cf75082f54
Коммит
1217f018ff
|
@ -4,6 +4,7 @@ try {
|
|||
Cu.import("resource://weave/async.js");
|
||||
Cu.import("resource://weave/auth.js");
|
||||
Cu.import("resource://weave/identity.js");
|
||||
Cu.import("resource://weave/resource.js");
|
||||
Cu.import("resource://weave/base_records/wbo.js");
|
||||
} catch (e) { do_throw(e); }
|
||||
|
||||
|
@ -11,11 +12,18 @@ Function.prototype.async = Async.sugar;
|
|||
|
||||
function record_handler(metadata, response) {
|
||||
let obj = {id: "asdf-1234-asdf-1234",
|
||||
modified: "2454725.98283",
|
||||
modified: 2454725.98283,
|
||||
payload: JSON.stringify({cheese: "roquefort"})};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function record_handler2(metadata, response) {
|
||||
let obj = {id: "record2",
|
||||
modified: 2454725.98284,
|
||||
payload: JSON.stringify({cheese: "gruyere"})};
|
||||
return httpd_basic_auth_handler(JSON.stringify(obj), metadata, response);
|
||||
}
|
||||
|
||||
function async_test() {
|
||||
let self = yield;
|
||||
let server;
|
||||
|
@ -26,20 +34,34 @@ function async_test() {
|
|||
|
||||
log.info("Setting up server and authenticator");
|
||||
|
||||
server = httpd_setup({"/record": record_handler});
|
||||
server = httpd_setup({"/record": record_handler,
|
||||
"/record2": record_handler2});
|
||||
|
||||
let auth = new BasicAuthenticator(new Identity("secret", "guest", "guest"));
|
||||
Auth.defaultAuthenticator = auth;
|
||||
|
||||
log.info("Getting a WBO record");
|
||||
|
||||
let res = new WBORecord("http://localhost:8080/record");
|
||||
let rec = yield res.get(self.cb);
|
||||
let res = new Resource("http://localhost:8080/record");
|
||||
yield res.get(self.cb);
|
||||
|
||||
let rec = new WBORecord(res.uri.spec);
|
||||
rec.deserialize(res.data);
|
||||
|
||||
do_check_eq(rec.id, "record"); // NOT "asdf-1234-asdf-1234"!
|
||||
do_check_eq(rec.modified, 2454725.98283);
|
||||
do_check_eq(typeof(rec.payload), "object");
|
||||
do_check_eq(rec.payload.cheese, "roquefort");
|
||||
do_check_eq(res.lastRequest.status, 200);
|
||||
do_check_eq(res.lastChannel.responseStatus, 200);
|
||||
|
||||
log.info("Getting a WBO record using the record manager");
|
||||
|
||||
let rec2 = yield Records.get(self.cb, "http://localhost:8080/record2");
|
||||
do_check_eq(rec2.id, "record2");
|
||||
do_check_eq(rec2.modified, 2454725.98284);
|
||||
do_check_eq(typeof(rec2.payload), "object");
|
||||
do_check_eq(rec2.payload.cheese, "gruyere");
|
||||
do_check_eq(Records.lastResource.lastChannel.responseStatus, 200);
|
||||
|
||||
log.info("Done!");
|
||||
do_test_finished();
|
||||
|
|
Загрузка…
Ссылка в новой задаче