Skip to content

Commit 697e38e

Browse files
added RecordScanner tests for findRecords and findRecord
1 parent d52f0cd commit 697e38e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

sdk/tests/record-scanner.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,41 @@ describe("RecordScanner", () => {
232232
expect(request.headers.get("Content-Type")).to.equal("application/json");
233233
});
234234

235+
it("should return OwnedRecord after successfully getting owned record", async () => {
236+
recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org", account: defaultAccount });
237+
const mockRegisterResponse = {
238+
ok: true,
239+
status: 201,
240+
text: () => Promise.resolve('{"uuid": "test-uuid"}'),
241+
json: () => Promise.resolve({ uuid: "test-uuid" })
242+
};
243+
fetchStub.resolves(mockRegisterResponse);
244+
await recordScanner.register(0);
245+
246+
fetchStub.resetHistory();
247+
248+
const mockResponse = {
249+
ok: true,
250+
status: 200,
251+
text: () => Promise.resolve(JSON.stringify(OWNED_RECORDS)),
252+
json: () => Promise.resolve(OWNED_RECORDS),
253+
};
254+
fetchStub.resolves(mockResponse);
255+
const ownedRecord = await recordScanner.findRecord({
256+
uuid: "test-uuid",
257+
});
258+
expect(ownedRecord).to.deep.equal(OWNED_RECORDS[0]);
259+
260+
const request = fetchStub.firstCall.args[0] as Request;
261+
const body = await request.text();
262+
const expectedBody = JSON.stringify({
263+
uuid: "test-uuid",
264+
});
265+
expect(body).to.equal(expectedBody);
266+
expect(request.method).to.equal("POST");
267+
expect(request.headers.get("Content-Type")).to.equal("application/json");
268+
});
269+
235270
it("should throw an error if the uuid is not registered", async () => {
236271
recordScanner = new RecordScanner({ url: "https://record-scanner.aleo.org", account: defaultAccount });
237272
let failed = false;

0 commit comments

Comments
 (0)