-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cu): implement tests and fixes #98
- Loading branch information
1 parent
6b537d9
commit bfaba47
Showing
12 changed files
with
509 additions
and
263 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable no-throw-literal */ | ||
import { describe, test } from 'node:test' | ||
import assert from 'node:assert' | ||
|
||
import { loadMessageMetaSchema } from '../dal.js' | ||
import { loadMessageMetaWith } from './ao-su.js' | ||
|
||
describe('ao-su', () => { | ||
describe('loadMessageMetaWith', () => { | ||
test('return the message meta', async () => { | ||
const loadMessageMeta = loadMessageMetaSchema.implement( | ||
loadMessageMetaWith({ | ||
fetch: async (url, options) => { | ||
assert.equal(url, 'https://ao-su-1.onrender.com/message/message-tx-123') | ||
assert.deepStrictEqual(options, { method: 'GET' }) | ||
|
||
return new Response(JSON.stringify({ | ||
processId: 'process-123', | ||
sortKey: 'block-123,time-456,hash-789' | ||
})) | ||
}, | ||
SU_URL: 'https://ao-su-1.onrender.com' | ||
}) | ||
) | ||
|
||
const res = await loadMessageMeta({ messageTxId: 'message-tx-123' }) | ||
|
||
assert.deepStrictEqual(res, { | ||
processId: 'process-123', | ||
sortKey: 'block-123,time-456,hash-789' | ||
}) | ||
}) | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -1,8 +1,66 @@ | ||
/* eslint-disable no-throw-literal */ | ||
import { describe, test } from 'node:test' | ||
import assert from 'node:assert' | ||
|
||
import { gatherScheduledMessagesWith } from './gatherScheduledMessages.js' | ||
|
||
describe('gatherScheduledMessages', () => { | ||
test('flatten and append all messages within the range', async () => { | ||
// TODO: implement tests | ||
test('should filter down to only the scheduled messages and append to ctx', async () => { | ||
const scheduledSortKey = 'block-123,time-456,hash-789,10_blocks1' | ||
const notScheduledSortKey = 'block-123,time-456,hash-789' | ||
|
||
const mockEval = { | ||
processId: 'process-123', | ||
message: { target: 'process-456', owner: 'owner-123', tags: [] }, | ||
evaluatedAt: new Date() | ||
} | ||
const gatherScheduledMessages = gatherScheduledMessagesWith({ | ||
findEvaluations: async ({ processId, from, to }) => { | ||
assert.equal(processId, 'process-123') | ||
assert.equal(from, 'block-122,time-456,hash-789') | ||
assert.equal(to, 'block-124,time-456,hash-789') | ||
|
||
return [ | ||
{ | ||
...mockEval, | ||
sortKey: scheduledSortKey, | ||
output: { state: { foo: 'bar' }, result: { messages: [{ foo: '1' }, { fizz: '2' }] } } | ||
}, | ||
// Scheduled message, but no output.result.messages | ||
{ | ||
sortKey: scheduledSortKey, | ||
...mockEval, | ||
output: { state: { foo: 'bar' } } | ||
}, | ||
// Not a scheduled message | ||
{ | ||
sortKey: notScheduledSortKey, | ||
...mockEval, | ||
output: { state: { foo: 'bar' }, result: { messages: [{ foo: '3' }, { fizz: '4' }] } } | ||
}, | ||
{ | ||
...mockEval, | ||
sortKey: scheduledSortKey, | ||
output: { state: { foo: 'bar' }, result: { messages: [{ foo: '5' }] } } | ||
} | ||
] | ||
} | ||
}) | ||
|
||
const res = await gatherScheduledMessages({ | ||
processId: 'process-123', | ||
from: 'block-122,time-456,hash-789', | ||
to: 'block-124,time-456,hash-789' | ||
}).toPromise() | ||
|
||
assert.equal(res.processId, 'process-123') | ||
assert.equal(res.from, 'block-122,time-456,hash-789') | ||
assert.equal(res.to, 'block-124,time-456,hash-789') | ||
assert(res.messages) | ||
assert.equal(res.messages.length, 3) | ||
const [one, two, five] = res.messages | ||
assert.equal(one.foo, '1') | ||
assert.equal(two.fizz, '2') | ||
assert.equal(five.foo, '5') | ||
}) | ||
}) |
Oops, something went wrong.