Skip to content

Commit

Permalink
refactor(atlas-data): document as experimental and not fully implemen…
Browse files Browse the repository at this point in the history
…ted #36
  • Loading branch information
TillaTheHun0 committed Jun 14, 2023
1 parent 531f277 commit c24d63a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ Run the unit tests, lint, and check formatting run:
deno task test
```

> To run the integration tests, you will need an instance of MongoDB running. If you're developing
> in [`Gitpod`](https://gitpod.io), a MongoDB instance is automatically started for you
> To run the integration tests, you will need an instance of MongoDB running, along with setting
> `MONGO_URL` to your connection string. If you're developing in [`Gitpod`](https://gitpod.io), a
> MongoDB instance is automatically started for you
To run the tests on the adapter methods run:

Expand Down
20 changes: 10 additions & 10 deletions clients/atlas.test.ts → clients/atlas-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assertEquals, assertObjectMatch, assertThrows, deferred } from '../dev_deps.ts'

import { AtlasClient } from './atlas.ts'
import { AtlasDataClient } from './atlas-data.ts'

Deno.test('client - atlas', async (t) => {
Deno.test('client - atlas-data', async (t) => {
let fetchMock = deferred<{ url: string; init: RequestInit }>()

const happy = {
Expand All @@ -21,7 +21,7 @@ Deno.test('client - atlas', async (t) => {
}

await t.step('should append the method to the url', async () => {
const client = new AtlasClient(happy)
const client = new AtlasDataClient(happy)
fetchMock = deferred<{ url: string; init: RequestInit }>()

await client
Expand All @@ -39,7 +39,7 @@ Deno.test('client - atlas', async (t) => {

await t.step('should append the headers to the request', async (t) => {
await t.step('Content-Type and Accept', async () => {
const client = new AtlasClient(happy)
const client = new AtlasDataClient(happy)
fetchMock = deferred<{ url: string; init: RequestInit }>()

await client
Expand All @@ -56,7 +56,7 @@ Deno.test('client - atlas', async (t) => {

await t.step('auth', async (t) => {
await t.step('api-key', async () => {
const client = new AtlasClient(happy)
const client = new AtlasDataClient(happy)
fetchMock = deferred<{ url: string; init: RequestInit }>()

await client
Expand All @@ -71,7 +71,7 @@ Deno.test('client - atlas', async (t) => {
})

await t.step('jwtTokenString', async () => {
const client = new AtlasClient({
const client = new AtlasDataClient({
...happy,
auth: { jwtTokenString: 'foobar' },
})
Expand All @@ -89,7 +89,7 @@ Deno.test('client - atlas', async (t) => {
})

await t.step('email and password', async () => {
const client = new AtlasClient({
const client = new AtlasDataClient({
...happy,
auth: { email: '[email protected]', password: 'secret' },
})
Expand All @@ -111,7 +111,7 @@ Deno.test('client - atlas', async (t) => {

await t.step('should append the body to the request', async (t) => {
await t.step('database, collection, and dataSource', async () => {
const client = new AtlasClient(happy)
const client = new AtlasDataClient(happy)
fetchMock = deferred<{ url: string; init: RequestInit }>()

await client
Expand All @@ -129,7 +129,7 @@ Deno.test('client - atlas', async (t) => {
})

await t.step('options', async () => {
const client = new AtlasClient(happy)
const client = new AtlasDataClient(happy)
fetchMock = deferred<{ url: string; init: RequestInit }>()

await client
Expand All @@ -149,6 +149,6 @@ Deno.test('client - atlas', async (t) => {
await t.step('should throw if credentials are not provided', () => {
// deno-lint-ignore ban-ts-comment
// @ts-expect-error
assertThrows(() => new AtlasClient({ ...happy, auth: {} }))
assertThrows(() => new AtlasDataClient({ ...happy, auth: {} }))
})
})
16 changes: 10 additions & 6 deletions clients/atlas.ts → clients/atlas-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { HyperErr } from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-utils%40v0.1.1/packages/utils/hyper-err.js'
import { EJSON } from '../deps.ts'
/**
* Not fully implemented or tested
*
* See https://github.com/hyper63/hyper-adapter-mongodb/issues/36
*/
import { EJSON, HyperErr } from '../deps.ts'
import type { AuthOptions, Document } from '../types.ts'

import type {
Expand All @@ -9,7 +13,7 @@ import type {
MongoInstanceClient,
} from './types.ts'

export class AtlasClient implements MongoInstanceClient {
export class AtlasDataClient implements MongoInstanceClient {
dataSource: string
endpoint: string
fetch = fetch
Expand Down Expand Up @@ -52,9 +56,9 @@ export class AtlasClient implements MongoInstanceClient {

export class Database implements MongoDatabaseClient {
name: string
client: AtlasClient
client: AtlasDataClient

constructor(name: string, client: AtlasClient) {
constructor(name: string, client: AtlasDataClient) {
this.name = name
this.client = client
}
Expand Down Expand Up @@ -82,7 +86,7 @@ export class Database implements MongoDatabaseClient {
export class Collection<T extends Document> implements MongoCollectionClient<T> {
name: string
database: Database
client: AtlasClient
client: AtlasDataClient

constructor(name: string, database: Database) {
this.name = name
Expand Down
15 changes: 9 additions & 6 deletions mod.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert, assertRejects, dataPort, pluginFactory } from './dev_deps.ts'

import { AtlasClient } from './clients/atlas.ts'
import { AtlasDataClient } from './clients/atlas-data.ts'
import factory from './mod.ts'
import { MetaDb } from './meta.ts'

Expand All @@ -21,11 +21,14 @@ Deno.test('mod', async (t) => {
})

await t.step('load', async (t) => {
await t.step('should construct an Atlas Data client and MetaDb client', async () => {
const { client, meta } = await factory(happy).load()
assert(client instanceof AtlasClient)
assert(meta instanceof MetaDb)
})
await t.step(
'should construct an AtlasData client and MetaDb client',
async () => {
const { client, meta } = await factory(happy).load()
assert(client instanceof AtlasDataClient)
assert(meta instanceof MetaDb)
},
)

await t.step('should throw if the provided url is not valid', async () => {
await assertRejects(() =>
Expand Down
6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AdapterConfig } from './types.ts'
import PORT_NAME from './port_name.ts'

import { AtlasClient } from './clients/atlas.ts'
import { AtlasDataClient } from './clients/atlas-data.ts'
import { NativeClient } from './clients/native.ts'
import type { MongoInstanceClient } from './clients/types.ts'

Expand All @@ -16,7 +16,7 @@ export default (config: AdapterConfig) => ({
port: PORT_NAME,
load: async () => {
const url = new URL(config.url)
let client: NativeClient | AtlasClient
let client: NativeClient | AtlasDataClient

if (isNative(url)) {
client = new NativeClient({ url: config.url })
Expand All @@ -27,7 +27,7 @@ export default (config: AdapterConfig) => ({
'options.atlas is required when using an Atlas Data url',
)
}
client = new AtlasClient({
client = new AtlasDataClient({
...config.options.atlas,
endpoint: config.url,
fetch,
Expand Down

0 comments on commit c24d63a

Please sign in to comment.