convert test files

This commit is contained in:
Felicio Mununga 2022-05-30 16:05:22 +02:00
parent e2d8c95a7b
commit a52e0306ce
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
4 changed files with 35 additions and 67 deletions

View File

@ -1,4 +1,3 @@
import { expect } from 'chai'
import { Waku } from 'js-waku' import { Waku } from 'js-waku'
import { Community } from './community' import { Community } from './community'
@ -6,16 +5,7 @@ import { Community } from './community'
import type { CommunityDescription } from './wire/community_description' import type { CommunityDescription } from './wire/community_description'
describe('Community [live data]', () => { describe('Community [live data]', () => {
before(function () { test('Retrieves community description For DappConnect Test from Waku prod fleet', async () => {
if (process.env.CI) {
// Skip live data test in CI
this.skip()
}
})
it('Retrieves community description For DappConnect Test from Waku prod fleet', async function () {
this.timeout(20000)
// FIXME?: mock
const waku = await Waku.create({ bootstrap: { default: true } }) const waku = await Waku.create({ bootstrap: { default: true } })
await waku.waitForRemotePeer() await waku.waitForRemotePeer()
@ -25,20 +15,20 @@ describe('Community [live data]', () => {
waku waku
) )
const desc = community.description as CommunityDescription const desc = community.description as CommunityDescription
expect(desc).to.not.be.undefined expect(desc).toBeDefined()
expect(desc.identity?.displayName).to.eq('Test Community') expect(desc.identity?.displayName).toEqual('Test Community')
const descChats = Array.from(desc.chats.values()).map( const descChats = Array.from(desc.chats.values()).map(
chat => chat?.identity?.displayName chat => chat?.identity?.displayName
) )
expect(descChats).to.include('Test Chat') expect(descChats).toEqual(expect.arrayContaining(['Test Chat']))
expect(descChats).to.include('Additional Chat') expect(descChats).toEqual(expect.arrayContaining(['Additional Chat']))
const chats = Array.from(community.chats.values()).map( const chats = Array.from(community.chats.values()).map(
chat => chat?.communityChat?.identity?.displayName chat => chat?.communityChat?.identity?.displayName
) )
expect(chats).to.include('Test Chat') expect(chats).toEqual(expect.arrayContaining(['Test Chat']))
expect(chats).to.include('Additional Chat') expect(chats).toEqual(expect.arrayContaining(['Additional Chat']))
}) })
}) })

View File

@ -1,23 +1,21 @@
import { expect } from 'chai'
import { createSymKeyFromPassword } from './encryption' import { createSymKeyFromPassword } from './encryption'
describe('Encryption', () => { describe('Encryption', () => {
it('Generate symmetric key from password', async function () { test('Generate symmetric key from password', async () => {
const str = 'arbitrary data here' const str = 'arbitrary data here'
const symKey = await createSymKeyFromPassword(str) const symKey = await createSymKeyFromPassword(str)
expect(Buffer.from(symKey).toString('hex')).to.eq( expect(Buffer.from(symKey).toString('hex')).toEqual(
'c49ad65ebf2a7b7253bf400e3d27719362a91b2c9b9f54d50a69117021666c33' 'c49ad65ebf2a7b7253bf400e3d27719362a91b2c9b9f54d50a69117021666c33'
) )
}) })
it('Generate symmetric key from password for chat', async function () { test('Generate symmetric key from password for chat', async () => {
const str = const str =
'0x02dcec6041fb999d65f1d33363e08c93d3c1f6f0fbbb26add383e2cf46c2b921f41dc14fd8-9a8b-4df5-a358-2c3067be5439' '0x02dcec6041fb999d65f1d33363e08c93d3c1f6f0fbbb26add383e2cf46c2b921f41dc14fd8-9a8b-4df5-a358-2c3067be5439'
const symKey = await createSymKeyFromPassword(str) const symKey = await createSymKeyFromPassword(str)
expect(Buffer.from(symKey).toString('hex')).to.eq( expect(Buffer.from(symKey).toString('hex')).toEqual(
'76ff5bf0a74a8e724367c7fc003f066d477641f468768a8da2817addf5c2ce76' '76ff5bf0a74a8e724367c7fc003f066d477641f468768a8da2817addf5c2ce76'
) )
}) })

View File

@ -1,4 +1,3 @@
import { expect } from 'chai'
import debug from 'debug' import debug from 'debug'
import { Protocols } from 'js-waku' import { Protocols } from 'js-waku'
@ -20,9 +19,7 @@ describe('Messenger', () => {
let identityAlice: Identity let identityAlice: Identity
let identityBob: Identity let identityBob: Identity
beforeEach(async function () { beforeEach(async () => {
this.timeout(20_000)
dbg('Generate keys') dbg('Generate keys')
identityAlice = Identity.generate() identityAlice = Identity.generate()
identityBob = Identity.generate() identityBob = Identity.generate()
@ -51,9 +48,7 @@ describe('Messenger', () => {
dbg('Messengers ready') dbg('Messengers ready')
}) })
it('Sends & Receive public chat messages', async function () { test('Sends & Receive public chat messages', async () => {
this.timeout(10_000)
await messengerAlice.joinChatById(testChatId) await messengerAlice.joinChatById(testChatId)
await messengerBob.joinChatById(testChatId) await messengerBob.joinChatById(testChatId)
@ -73,12 +68,10 @@ describe('Messenger', () => {
const receivedMessage = await receivedMessagePromise const receivedMessage = await receivedMessagePromise
expect(receivedMessage.chatMessage?.text).to.eq(text) expect(receivedMessage.chatMessage?.text).toEqual(text)
}) })
it('public chat messages have signers', async function () { test('public chat messages have signers', async () => {
this.timeout(10_000)
await messengerAlice.joinChatById(testChatId) await messengerAlice.joinChatById(testChatId)
await messengerBob.joinChatById(testChatId) await messengerBob.joinChatById(testChatId)
@ -99,32 +92,22 @@ describe('Messenger', () => {
const receivedMessage = await receivedMessagePromise const receivedMessage = await receivedMessagePromise
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(bufToHex(receivedMessage.signer!)).to.eq( expect(bufToHex(receivedMessage.signer!)).toEqual(
bufToHex(identityAlice.publicKey) bufToHex(identityAlice.publicKey)
) )
}) })
afterEach(async function () { afterEach(async () => {
this.timeout(5000)
await messengerAlice.stop() await messengerAlice.stop()
await messengerBob.stop() await messengerBob.stop()
}) })
}) })
describe('Messenger [live data]', () => { describe('Messenger [live data]', () => {
before(function () {
if (process.env.CI) {
// Skip live data test in CI
this.skip()
}
})
let messenger: Messenger let messenger: Messenger
let identity: Identity let identity: Identity
beforeEach(async function () { beforeEach(async () => {
this.timeout(20_000)
dbg('Generate keys') dbg('Generate keys')
identity = Identity.generate() identity = Identity.generate()
@ -139,9 +122,7 @@ describe('Messenger [live data]', () => {
dbg('Messengers ready') dbg('Messengers ready')
}) })
it('Receive public chat messages', async function () { test('Receive public chat messages', async () => {
this.timeout(20_000)
const community = await Community.instantiateCommunity( const community = await Community.instantiateCommunity(
'0x02cf13719c8b836bebd4e430c497ee38e798a43e4d8c4760c34bbd9bf4f2434d26', '0x02cf13719c8b836bebd4e430c497ee38e798a43e4d8c4760c34bbd9bf4f2434d26',
messenger.waku messenger.waku
@ -172,8 +153,7 @@ describe('Messenger [live data]', () => {
) )
}) })
afterEach(async function () { afterEach(async () => {
this.timeout(5000)
await messenger.stop() await messenger.stop()
}) })
}) })

View File

@ -1,5 +1,3 @@
import { expect } from 'chai'
import { import {
AudioMessage_AudioType, AudioMessage_AudioType,
ChatMessage_ContentType, ChatMessage_ContentType,
@ -10,7 +8,7 @@ import { ChatMessage, ContentType } from './chat_message'
import type { AudioContent, ImageContent, StickerContent } from './chat_message' import type { AudioContent, ImageContent, StickerContent } from './chat_message'
describe('Chat Message', () => { describe('Chat Message', () => {
it('Encode & decode Image message', () => { test('Encode & decode Image message', () => {
const payload = Buffer.from([1, 1]) const payload = Buffer.from([1, 1])
const imageContent: ImageContent = { const imageContent: ImageContent = {
@ -24,12 +22,12 @@ describe('Chat Message', () => {
const buf = message.encode() const buf = message.encode()
const dec = ChatMessage.decode(buf) const dec = ChatMessage.decode(buf)
expect(dec.contentType).eq(ChatMessage_ContentType.CONTENT_TYPE_IMAGE) expect(dec.contentType).toEqual(ChatMessage_ContentType.CONTENT_TYPE_IMAGE)
expect(dec.image?.payload?.toString()).eq(payload.toString()) expect(dec.image?.payload?.toString()).toEqual(payload.toString())
expect(dec.image?.type).eq(ImageType.IMAGE_TYPE_PNG) expect(dec.image?.type).toEqual(ImageType.IMAGE_TYPE_PNG)
}) })
it('Encode & decode Audio message', () => { test('Encode & decode Audio message', () => {
const payload = Buffer.from([1, 1]) const payload = Buffer.from([1, 1])
const durationMs = 12345 const durationMs = 12345
@ -45,13 +43,13 @@ describe('Chat Message', () => {
const buf = message.encode() const buf = message.encode()
const dec = ChatMessage.decode(buf) const dec = ChatMessage.decode(buf)
expect(dec.contentType).eq(ChatMessage_ContentType.CONTENT_TYPE_AUDIO) expect(dec.contentType).toEqual(ChatMessage_ContentType.CONTENT_TYPE_AUDIO)
expect(dec.audio?.payload?.toString()).eq(payload.toString()) expect(dec.audio?.payload?.toString()).toEqual(payload.toString())
expect(dec.audio?.type).eq(ImageType.IMAGE_TYPE_PNG) expect(dec.audio?.type).toEqual(ImageType.IMAGE_TYPE_PNG)
expect(dec.audio?.durationMs).eq(durationMs) expect(dec.audio?.durationMs).toEqual(durationMs)
}) })
it('Encode & decode Sticker message', () => { test('Encode & decode Sticker message', () => {
const hash = 'deadbeef' const hash = 'deadbeef'
const pack = 12345 const pack = 12345
@ -66,8 +64,10 @@ describe('Chat Message', () => {
const buf = message.encode() const buf = message.encode()
const dec = ChatMessage.decode(buf) const dec = ChatMessage.decode(buf)
expect(dec.contentType).eq(ChatMessage_ContentType.CONTENT_TYPE_STICKER) expect(dec.contentType).toEqual(
expect(dec.sticker?.hash).eq(hash) ChatMessage_ContentType.CONTENT_TYPE_STICKER
expect(dec.sticker?.pack).eq(pack) )
expect(dec.sticker?.hash).toEqual(hash)
expect(dec.sticker?.pack).toEqual(pack)
}) })
}) })