Skip to content
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
5 changes: 3 additions & 2 deletions src/web3telegram/sendTelegram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
DappWhitelistAddressConsumer &
IpfsNodeConfigConsumer &
IpfsGatewayConfigConsumer &
SendTelegramParams): Promise<SendTelegramResponse> => {

Check warning on line 59 in src/web3telegram/sendTelegram.ts

View workflow job for this annotation

GitHub Actions / check-code

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed

Check warning on line 59 in src/web3telegram/sendTelegram.ts

View workflow job for this annotation

GitHub Actions / npm-publish-dry-run / publish-npm / build

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
try {
const vDatasetAddress = addressOrEnsSchema()
.required()
Expand Down Expand Up @@ -279,7 +279,7 @@
const requestorder = await iexec.order.signRequestorder(requestorderToSign);

// Match orders and compute task ID
const { dealid } = await iexec.order.matchOrders(
const { dealid: dealId } = await iexec.order.matchOrders(
{
apporder: apporder,
datasetorder: datasetorder,
Expand All @@ -288,13 +288,14 @@
},
{ useVoucher: vUseVoucher }
);
const taskId = await iexec.deal.computeTaskId(dealid, 0);
const taskId = await iexec.deal.computeTaskId(dealId, 0);
return {
dealId,
taskId,
};
} catch (error) {
// Protocol error detected, re-throwing as-is
if ((error as any)?.isProtocolError === true) {

Check warning on line 298 in src/web3telegram/sendTelegram.ts

View workflow job for this annotation

GitHub Actions / check-code

Unexpected any. Specify a different type

Check warning on line 298 in src/web3telegram/sendTelegram.ts

View workflow job for this annotation

GitHub Actions / npm-publish-dry-run / publish-npm / build

Unexpected any. Specify a different type
throw error;
}
// Handle protocol errors - this will throw if it's an ApiCallError
Expand Down
1 change: 1 addition & 0 deletions src/web3telegram/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type SendTelegramParams = {

export type SendTelegramResponse = {
taskId: string;
dealId: string;
};

export type PrepareTelegramCampaignParams = {
Expand Down
87 changes: 36 additions & 51 deletions tests/e2e/sendTelegram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ describe('web3telegram.sendTelegram()', () => {
protectedData: validProtectedData.address,
workerpoolMaxPrice: prodWorkerpoolPublicPrice,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand Down Expand Up @@ -290,12 +288,10 @@ describe('web3telegram.sendTelegram()', () => {
protectedData: validProtectedData.address,
workerpoolAddressOrEns: learnProdWorkerpoolAddress,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand Down Expand Up @@ -323,11 +319,10 @@ describe('web3telegram.sendTelegram()', () => {
workerpoolAddressOrEns: learnProdWorkerpoolAddress,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand All @@ -344,11 +339,10 @@ describe('web3telegram.sendTelegram()', () => {
workerpoolAddressOrEns: learnProdWorkerpoolAddress,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand All @@ -365,11 +359,10 @@ describe('web3telegram.sendTelegram()', () => {
});
expect(sendTelegramResponse).toBeDefined();
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand All @@ -387,12 +380,10 @@ describe('web3telegram.sendTelegram()', () => {
senderName: 'Product Team',
workerpoolAddressOrEns: learnProdWorkerpoolAddress,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
);
Expand All @@ -406,12 +397,10 @@ describe('web3telegram.sendTelegram()', () => {
workerpoolAddressOrEns: learnProdWorkerpoolAddress,
label: 'ID1234678',
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
// TODO check label in created deal
},
2 * MAX_EXPECTED_BLOCKTIME + MAX_EXPECTED_WEB2_SERVICES_TIME
Expand Down Expand Up @@ -500,12 +489,10 @@ describe('web3telegram.sendTelegram()', () => {
// workerpoolAddressOrEns: prodWorkerpoolAddress, // default
useVoucher: true,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME +
MAX_EXPECTED_WEB2_SERVICES_TIME +
Expand Down Expand Up @@ -561,12 +548,10 @@ describe('web3telegram.sendTelegram()', () => {
workerpoolMaxPrice: nonSponsoredAmount,
useVoucher: true,
});
expect('taskId' in sendTelegramResponse).toBe(true);
expect(
'taskId' in sendTelegramResponse
? sendTelegramResponse.taskId
: undefined
).toBeDefined();
expect(sendTelegramResponse).toStrictEqual({
dealId: expect.any(String),
taskId: expect.any(String),
});
},
2 * MAX_EXPECTED_BLOCKTIME +
MAX_EXPECTED_WEB2_SERVICES_TIME +
Expand Down
Loading