Skip to content

Commit

Permalink
Simplify types
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 16, 2024
1 parent 68e695e commit 39d5ca8
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,37 @@ describe('GenericPayloadDiviner', () => {
describe('single', () => {
it.each(['network.xyo.test', 'network.xyo.debug'])('only returns payloads of that schema', async (schema) => {
const schemas = [schema]
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
.fields({ schemas })
.build()
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema }).fields({ schemas }).build()
const results = await sut.divine([query])
expect(results.length).toBeGreaterThan(0)
expect(results.every(result => result.schema === schema)).toBe(true)
})
it('only return single payload of that schema', async () => {
const schemas = ['network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({ limit: 1, schemas })
.build()
const results = await sut.divine([query])
expect(results.length).toBe(1)
expect(await PayloadBuilder.dataHash(results[0])).toBe(await PayloadBuilder.dataHash(payloadD))
expect(await PayloadBuilder.dataHash(results[0])).toBe(await PayloadBuilder.dataHash(insertedPayloads[3]))
expect(results.every(result => result.schema === 'network.xyo.debug')).toBe(true)
})
it('only return single payload of that schema (desc)', async () => {
const schemas = ['network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 1, order: 'desc', schemas,
})
.build()
const results = await sut.divine([query])
expect(results.length).toBe(1)
expect(PayloadBuilder.omitStorageMeta(results[0])).toStrictEqual(payloadD)
expect(await PayloadBuilder.dataHash(results[0])).toBe(await PayloadBuilder.dataHash(payloadD))
expect(PayloadBuilder.omitStorageMeta(results[0])).toStrictEqual(insertedPayloads[3])
expect(await PayloadBuilder.dataHash(results[0])).toBe(await PayloadBuilder.dataHash(insertedPayloads[3]))
expect(results.every(result => result.schema === 'network.xyo.debug')).toBe(true)
})
it('only return single payload of that schema (asc)', async () => {
const schemas = ['network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 1, order: 'asc', schemas,
})
Expand All @@ -126,7 +124,7 @@ describe('GenericPayloadDiviner', () => {
describe('multiple', () => {
it('only returns payloads of that schema', async () => {
const schemas = ['network.xyo.test', 'network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({ schemas })
.build()
const results = await sut.divine([query])
Expand All @@ -137,7 +135,7 @@ describe('GenericPayloadDiviner', () => {
describe('paging', () => {
it('test paging with multiple calls (asc)', async () => {
const schemas = ['network.xyo.test', 'network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, order: 'asc', schemas,
})
Expand All @@ -151,7 +149,7 @@ describe('GenericPayloadDiviner', () => {
expect(resultSequences[1]).toBe(insertedPayloads[1]._sequence)

const cursor = resultSequences[1]
const query2 = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query2 = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, cursor, order: 'asc', schemas,
})
Expand All @@ -163,7 +161,7 @@ describe('GenericPayloadDiviner', () => {
expect(resultSequences2[1]).toBe(insertedPayloads[3]._sequence)
const cursor2 = resultSequences2[1]

const query3 = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query3 = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, cursor: cursor2, order: 'asc', schemas,
})
Expand All @@ -173,7 +171,7 @@ describe('GenericPayloadDiviner', () => {
})
it('test paging with multiple calls (desc)', async () => {
const schemas = ['network.xyo.test', 'network.xyo.debug']
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, order: 'desc', schemas,
})
Expand All @@ -185,7 +183,7 @@ describe('GenericPayloadDiviner', () => {
expect(resultSequences[1]).toBe(insertedPayloads[2]._sequence)

const cursor = resultSequences[1]
const query2 = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query2 = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, cursor, order: 'desc', schemas,
})
Expand All @@ -197,7 +195,7 @@ describe('GenericPayloadDiviner', () => {
expect(resultSequences2[1]).toBe(insertedPayloads[0]._sequence)
const cursor2 = resultSequences2[1]

const query3 = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash>>({ schema: PayloadDivinerQuerySchema })
const query3 = new PayloadBuilder<PayloadDivinerQueryPayload>({ schema: PayloadDivinerQuerySchema })
.fields({
limit: 2, cursor: cursor2, order: 'desc', schemas,
})
Expand All @@ -212,7 +210,7 @@ describe('GenericPayloadDiviner', () => {
it('only returns payloads with that property', async () => {
type WithUrl = { url?: string }
const url = payloadA.url
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash> & WithUrl>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload & WithUrl>({ schema: PayloadDivinerQuerySchema })
.fields({ url })
.build()
const results = await sut.divine([query])
Expand All @@ -224,7 +222,7 @@ describe('GenericPayloadDiviner', () => {
const cases: string[][] = [['bar'], ['baz'], ['bar', 'baz']]
it.each(cases)('only returns payloads that have an array containing all the values supplied', async (...foo) => {
type WithFoo = { foo?: string[] }
const query = new PayloadBuilder<PayloadDivinerQueryPayload<EmptyObject, Hash> & WithFoo>({ schema: PayloadDivinerQuerySchema })
const query = new PayloadBuilder<PayloadDivinerQueryPayload & WithFoo>({ schema: PayloadDivinerQuerySchema })
.fields({ foo })
.build()
const results = await sut.divine([query])
Expand Down

0 comments on commit 39d5ca8

Please sign in to comment.