Skip to content

Commit

Permalink
fix sync test and expect results of sync call
Browse files Browse the repository at this point in the history
  • Loading branch information
nomo-app committed Nov 16, 2023
1 parent b4b352d commit b5945f2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
21 changes: 19 additions & 2 deletions dist/send_message/send_message.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nomoSendMessage = void 0;
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const server = 'https://zeniq.chat/';
/**
* TODO: document here
*/
async function nomoSendMessage(args) {
console.log("nomoSendMessage not implemented");
async function nomoSendMessage(args, accessToken) {
let { roomId, content, transationID, eventType } = args;
const url = server + `_matrix/client/v3/rooms/${roomId}/send/${eventType}/${transationID}`;
try {
const response = await axios_1.default.put(url, content, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
return response.data['event_id'];
}
catch (error) {
console.error('Error sending message:', error);
return "";
}
}
exports.nomoSendMessage = nomoSendMessage;
9 changes: 4 additions & 5 deletions dist/syncing/sync_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ async function nomoSyncUser(accessToken, since, filter, setPresence, fullState)
// If the access_token is required as a query parameter
// 'access_token': accessToken,
// 'filter': filter, // The sync filter to use
'since': since, // Pass the 'since' token from the previous sync or initial login
// 'since': since, // Pass the 'since' token from the previous sync or initial login
// 'set_presence': setPresence, // Controls the presence state of the client
// 'timeout': 1000, // The maximum time to wait, in milliseconds
// 'full_state': fullState, // Whether to include full state or not
'full_state': true, // Whether to include full state or not
}
}).catch(console.error);
;
console.table(res === null || res === void 0 ? void 0 : res.data);
});
return res;
}
exports.nomoSyncUser = nomoSyncUser;
9 changes: 4 additions & 5 deletions src/syncing/sync_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ export async function nomoSyncUser(accessToken: string, since: string, filter: s
// If the access_token is required as a query parameter
// 'access_token': accessToken,
// 'filter': filter, // The sync filter to use
'since': since, // Pass the 'since' token from the previous sync or initial login
// 'since': since, // Pass the 'since' token from the previous sync or initial login
// 'set_presence': setPresence, // Controls the presence state of the client
// 'timeout': 1000, // The maximum time to wait, in milliseconds
// 'full_state': fullState, // Whether to include full state or not
'full_state': true, // Whether to include full state or not
}
}).catch(console.error);;

console.table(res?.data);
});
return res;
}
32 changes: 25 additions & 7 deletions test/syncing/sync_user.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { nomoRegisterOrLogin, nomoSyncUser, UserMatrix, nomoCreateFilter } from "../../src";
import { nomoRegisterOrLogin, nomoSyncUser, UserMatrix } from "../../src";

test("sync user", async () => {
const mnemonic = "diet say develop title sibling steel blast table chicken foster fuel giraffe";
const userMatrix: UserMatrix = await nomoRegisterOrLogin(mnemonic);
// const filterID: string = await nomoCreateFilter(userMatrix.access_token, userMatrix.user_id);
// await nomoSyncUser(userMatrix.access_token, "", '', "online", false);
// expect(userMatrix.user_id).toBe("@0x3f0e8cF0c6eb9789348541D9D0Ce4ac847277e9B:zeniq.chat");
}, 10000);
const mnemonic =
"diet say develop title sibling steel blast table chicken foster fuel giraffe";
const userMatrix: UserMatrix = await nomoRegisterOrLogin(mnemonic);

expect(userMatrix.user_id).toBe(
"@0xa563B68Ba292601968A4fb63861e9d847126E83E:zeniq.chat"
);
expect(userMatrix.home_server).toBe("zeniq.chat");

// const filterID: string = await nomoCreateFilter(userMatrix.access_token, userMatrix.user_id);
const res = await nomoSyncUser(
userMatrix.access_token,
"",
"",
"online",
false
);
expect(res.status).toBe(200);

const data = res.data;
console.log("sync data", data);

expect(data.rooms).toBeDefined();
}, 10000);

0 comments on commit b5945f2

Please sign in to comment.