Skip to content

Commit

Permalink
test: scaffold test suite #31 #32
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Jun 7, 2023
1 parent 0a13345 commit 19886f5
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
8 changes: 8 additions & 0 deletions adapter.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NativeClient } from './clients/native.ts'

import { suite } from './test/suite.ts'

const client = new NativeClient({ url: Deno.env.get('MONGO_URL') || 'mongodb://127.0.0.1:27017' })
await client.connect()

await suite(client)
7 changes: 7 additions & 0 deletions adapter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { suite } from './test/suite.ts'

// TODO: implement
// deno-lint-ignore no-explicit-any
const mockClient: any = {}

await suite(mockClient)
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"lineWidth": 100,
"singleQuote": true,
"semiColons": false
},
"test": {
"exclude": ["*.integration.test.ts"]
}
}
123 changes: 123 additions & 0 deletions test/suite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// deno-lint-ignore-file ban-ts-comment
import { assert } from '../dev_deps.ts'

import { adapter } from '../adapter.ts'
import { MongoInstanceClient } from '../clients/types.ts'
import { MetaDb } from '../meta.ts'

export const suite = (
client: MongoInstanceClient,
options: { shouldBaseLine: boolean } = { shouldBaseLine: false },
) => {
Deno.test(`Mongo Adapter Test Suite - '${client.constructor.name}'`, async (t) => {
const a = adapter({ client, meta: new MetaDb({ client, metaDbName: 'foobar' }) })

await t.step('baseline', async () => {
if (!options.shouldBaseLine) return assert(true)
const res = await a.removeDatabase('hyper~movies').catch((e) => {
if (e.status === 404) return { ok: true }
throw e
})
// @ts-expect-error
assert(res.ok)
})

await t.step('createDatabase', async (t) => {
await t.step('should create the database', async () => {
})

await t.step('should return a HyperErr(409) if database already exists', async () => {
})
})

await t.step('removeDatabase', async (t) => {
await t.step('should remove the database', async () => {
})

await t.step('should return a HyperErr(404) if database already exists', async () => {
})
})

await t.step('createDocument', async (t) => {
await t.step('should create the document, assigning the provided _id', async () => {
})

await t.step('should return a HyperErr(400) if the document is empty', async () => {
})

await t.step('should return a HyperErr(409) if the _id already exists', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('retrieveDocument', async (t) => {
await t.step('should retrieve the document', async () => {
})

await t.step('should return a HyperErr(404) if the document is not found', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('updateDocument', async (t) => {
await t.step('should update the document', async () => {
})

await t.step('should return a HyperErr(404) if the document is not found', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('removeDocument', async (t) => {
await t.step('should remove the document', async () => {
})

await t.step('should return a HyperErr(404) if the document is not found', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('queryDocuments', async (t) => {
await t.step('should return the documents that match the selector', async () => {
})

await t.step('should return an empty array if no documents are found', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('indexDocuments', async (t) => {
await t.step('should create the index', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('listDocuments', async (t) => {
await t.step('should return the list of documents', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})

await t.step('bulkDocuments', async (t) => {
await t.step('should perform the bulk operation', async () => {
})

await t.step('should return a HyperErr(404) if the database does not exist', async () => {
})
})
})
}

0 comments on commit 19886f5

Please sign in to comment.