Skip to content

Commit

Permalink
adress pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Nov 21, 2024
1 parent 026f7f7 commit 7d14017
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
1 change: 0 additions & 1 deletion packages/js-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"name": "@dm3-org/dm3-js-sdk",
"license": "BSD-2-Clause",
Expand Down
74 changes: 49 additions & 25 deletions packages/js-sdk/src/Dm3Sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('Dm3Sdk', () => {
ethers.Wallet.createRandom(),
'http://localhost:3000',
);
});

beforeAll(() => {
axiosMock = new MockAdapter(axios);

//Mock BackendConnector HttpRequests
Expand Down Expand Up @@ -102,9 +104,8 @@ describe('Dm3Sdk', () => {
});

await dm3.conversations.addConversation('bob.eth');
const c = dm3.conversations.list;
expect(c.length).toBe(1);
expect(c[0].contact.name).toBe('bob.eth');
expect(dm3.conversations.list.length).toBe(1);
expect(dm3.conversations.list[0].contact.name).toBe('bob.eth');
});
it('can multiple conversations to the contact list', async () => {
const mockTldResolver = {
Expand Down Expand Up @@ -156,12 +157,10 @@ describe('Dm3Sdk', () => {

await dm3.conversations.addConversation('bob.eth');
await dm3.conversations.addConversation('karl.eth');
const c = dm3.conversations.list;
dm3;
console.log(c);
expect(c.length).toBe(2);
expect(c[0].contact.name).toBe('bob.eth');
expect(c[1].contact.name).toBe('karl.eth');

expect(dm3.conversations.list.length).toBe(2);
expect(dm3.conversations.list[0].contact.name).toBe('bob.eth');
expect(dm3.conversations.list[1].contact.name).toBe('karl.eth');
});
it('dont add duplicate conversations', async () => {
const mockTldResolver = {
Expand Down Expand Up @@ -192,9 +191,8 @@ describe('Dm3Sdk', () => {

await dm3.conversations.addConversation('bob.eth');
await dm3.conversations.addConversation('bob.eth');
const c = dm3.conversations.list;
expect(c.length).toBe(1);
expect(c[0].contact.name).toBe('bob.eth');
expect(dm3.conversations.list.length).toBe(1);
expect(dm3.conversations.list[0].contact.name).toBe('bob.eth');
});
});

Expand Down Expand Up @@ -231,12 +229,25 @@ describe('Dm3Sdk', () => {

const msg1 = await msgFactory.createMessage('Hi');

const c = await dm3.conversations.addConversation('bob.eth');
expect(c?.messages.list().length).toBe(0);
await c?.messages.addMessage('bob.eth', msg1);

expect(c?.messages.list().length).toBe(1);
expect(c?.messages.list()[0].envelop.message.message).toBe('Hi');
expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list().length,
).toBe(0);
await (
await dm3.conversations.addConversation('bob.eth')
)?.messages.addMessage('bob.eth', msg1);

expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list().length,
).toBe(1);
expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list()[0].envelop.message.message,
).toBe('Hi');
});
it('can send a message', async () => {
const mockTldResolver = {
Expand Down Expand Up @@ -266,13 +277,26 @@ describe('Dm3Sdk', () => {
accountAddress: alice.address,
});

const c = await dm3.conversations.addConversation('bob.eth');
expect(c?.messages.list().length).toBe(0);

await c?.messages.sendMessage('Hi');

expect(c?.messages.list().length).toBe(1);
expect(c?.messages.list()[0].envelop.message.message).toBe('Hi');
expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list().length,
).toBe(0);

await (
await dm3.conversations.addConversation('bob.eth')
)?.messages.sendMessage('Hi');

expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list().length,
).toBe(1);
expect(
(
await dm3.conversations.addConversation('bob.eth')
)?.messages.list()[0].envelop.message.message,
).toBe('Hi');
});
});
});

0 comments on commit 7d14017

Please sign in to comment.