-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6446f2d
commit 297c8d4
Showing
6 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { TAgent, IDataStore, IMessageHandler, IMessage } from '../../packages/daf-core/src' | ||
import { IDataStoreORM } from '../../packages/daf-typeorm/src' | ||
|
||
type ConfiguredAgent = TAgent<IDataStore & IMessageHandler & IDataStoreORM> | ||
|
||
export default (testContext: { | ||
getAgent: () => ConfiguredAgent | ||
setup: () => Promise<boolean> | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
describe('message handler', () => { | ||
let agent: ConfiguredAgent | ||
|
||
beforeAll(async () => { | ||
await testContext.setup() | ||
agent = testContext.getAgent() | ||
return true | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
let parsedMessage: IMessage | ||
|
||
it('should parse raw message', async () => { | ||
const raw = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1ODg2NzY3MzksInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2N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await agent.handleMessage({ | ||
raw, | ||
save: false, | ||
metaData: [{type: 'test'}], | ||
}) | ||
expect(typeof parsedMessage.id).toEqual('string') | ||
|
||
}) | ||
|
||
it('should save message', async () => { | ||
const id = await agent.dataStoreSaveMessage({ message: parsedMessage }) | ||
expect(id).toEqual(parsedMessage.id) | ||
}) | ||
|
||
it('should get message from db', async () => { | ||
const message = await agent.dataStoreGetMessage({ id: parsedMessage.id }) | ||
expect(message).toEqual({...parsedMessage, ...{replyTo: null, replyUrl: null}}) | ||
}) | ||
|
||
it('should throw error for non existing message', async () => { | ||
await expect( | ||
agent.dataStoreGetMessage({ | ||
id: 'foobar', | ||
}), | ||
).rejects.toThrow('Message not found') | ||
}) | ||
|
||
it('should count messages', async () => { | ||
const allMessages = await agent.dataStoreORMGetMessages() | ||
const count = await agent.dataStoreORMGetMessagesCount() | ||
expect(allMessages.length).toEqual(count) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters