本文整理匯總了TypeScript中models/users/users_crud.UsersCRUD類的典型用法代碼示例。如果您正苦於以下問題:TypeScript UsersCRUD類的具體用法?TypeScript UsersCRUD怎麽用?TypeScript UsersCRUD使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了UsersCRUD類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("should make a patch request", (done) => {
const bulkUpdateUserJSON = {
users: ["bob", "alice"],
operations: {
enable: true
}
};
jasmine.Ajax.stubRequest(BULK_UPDATE_USERS_API, JSON.stringify(bulkUpdateUserJSON), "PATCH").andReturn({
status: 200,
responseHeaders: {
"Content-Type": "application/vnd.go.cd.v3+json; charset=utf-8",
"ETag": "some-etag"
},
responseText: JSON.stringify(
bulkUpdateUserJSON)
});
const onResponse = jasmine.createSpy().and.callFake((response: ApiResult<any>) => {
done();
} );
UsersCRUD.bulkUserStateUpdate(bulkUpdateUserJSON).then(onResponse);
const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toEqual(BULK_UPDATE_USERS_API);
expect(request.method).toEqual("PATCH");
expect(request.requestHeaders)
.toEqual({"Accept": "application/vnd.go.cd.v3+json", "Content-Type": "application/json; charset=utf-8"});
});
示例2: it
it("should make a get request", (done) => {
const userJSON = users()[0];
const GET_USER_API = "/go/api/users/bob";
jasmine.Ajax.stubRequest(GET_USER_API).andReturn({
status: 200,
responseHeaders: {
"Content-Type": "application/vnd.go.cd.v3+json; charset=utf-8",
"ETag": "some-etag"
},
responseText: JSON.stringify(
userJSON)
});
const onResponse = jasmine.createSpy().and.callFake((response: ApiResult<User>) => {
const responseJSON = response.unwrap() as SuccessResponse<User>;
expect(responseJSON.body.loginName()).toEqual(userJSON.login_name);
done();
});
UsersCRUD.get("bob").then(onResponse);
const request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toEqual(GET_USER_API);
expect(request.method).toEqual("GET");
expect(request.requestHeaders.Accept).toEqual("application/vnd.go.cd.v3+json");
});