Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EventResult should await OK response #299

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/keri/app/aiding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class Identifier {
jsondata[algo] = keeper.params();

this.client.pidx = this.client.pidx + 1;
const res = this.client.fetch('/identifiers', 'POST', jsondata);
const res = await this.client.fetch('/identifiers', 'POST', jsondata);
return new EventResult(serder, sigs, res);
}

Expand Down Expand Up @@ -447,7 +447,7 @@ export class Identifier {
sigs: sigs,
};

const res = this.client.fetch(
const res = await this.client.fetch(
'/identifiers/' + name + '/endroles',
'POST',
jsondata
Expand Down Expand Up @@ -500,16 +500,12 @@ export class Identifier {
export class EventResult {
private readonly _serder: Serder;
private readonly _sigs: string[];
private readonly promise: Promise<Response> | Response;
private readonly response: Response;

constructor(
serder: Serder,
sigs: string[],
promise: Promise<Response> | Response
) {
constructor(serder: Serder, sigs: string[], response: Response) {
this._serder = serder;
this._sigs = sigs;
this.promise = promise;
this.response = response;
}

get serder() {
Expand All @@ -521,7 +517,6 @@ export class EventResult {
}

async op(): Promise<any> {
const res = await this.promise;
return await res.json();
return await this.response.json();
}
}
18 changes: 18 additions & 0 deletions test/app/aiding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ describe('Aiding', () => {
assert.deepEqual(lastCall.body.salty.transferable, true);
});

it('Should throw error if fetch call fails when creating identifier', async () => {
const error = new Error(`Fail ${randomUUID()}`);
client.fetch.mockRejectedValue(error);
await expect(
client
.identifiers()
.create('aid1', { bran: '0123456789abcdefghijk' })
).rejects.toThrow(error);
});

it('Can rotate salty identifier', async () => {
const aid1 = await createMockIdentifierState('aid1', bran, {});
client.fetch.mockResolvedValueOnce(Response.json(aid1));
Expand Down Expand Up @@ -346,6 +356,14 @@ describe('Aiding', () => {
});
});

it('Should throw error if fetch call fails when adding end role', async () => {
const error = new Error(`Fail ${randomUUID()}`);
client.fetch.mockRejectedValue(error);
await expect(
client.identifiers().addEndRole('aid1', 'agent')
).rejects.toThrow(error);
});

it('Can get members', async () => {
client.fetch.mockResolvedValue(Response.json({}));
await client.identifiers().members('aid1');
Expand Down
Loading