Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/backend/api/CreateBackend.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {suite} from '@alinea/suite'
import {createRemote} from './CreateBackend.js'

const test = suite(import.meta)

test('createRemote routes write/getBlobs to later smart implementation and keeps history on github implementation', async () => {
let writes = 0
let revisions = 0
const remote = createRemote(
{
revisions: async () => {
revisions++
return []
},
revisionData: async () => undefined,
getTreeIfDifferent: async () => undefined
},
{
write: async () => {
writes++
return {sha: 'next'}
},
getBlobs: async function* () {
yield ['a'.repeat(40), new Uint8Array([1])]
}
}
)
await remote.write({} as any)
const blobs = Array<[string, Uint8Array]>()
for await (const blob of remote.getBlobs(['a'.repeat(40)])) blobs.push(blob)
await remote.revisions('x')
test.is(writes, 1)
test.is(revisions, 1)
test.is(blobs.length, 1)
})
7 changes: 6 additions & 1 deletion src/backend/api/CreateBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {assert} from 'alinea/core/util/Assert'
import * as driver from 'rado/driver'
import {BasicAuth} from './BasicAuth.js'
import {DatabaseApi} from './DatabaseApi.js'
import {GitSmartApi} from './GitSmartApi.js'
import {GithubApi, type GithubOptions} from './GithubApi.js'
import {OAuth2, type OAuth2Options} from './OAuth2.js'

Expand Down Expand Up @@ -57,12 +58,16 @@ export function createBackend(
author,
...options.github
})
const smartApi = new GitSmartApi({
author,
...options.github
})
const dbApi = new DatabaseApi(context, {db})
assert(options.oauth2 ?? options.auth, 'No auth method provided')
const auth = options.oauth2
? new OAuth2(context, config, options.oauth2)
: new BasicAuth(context, options.auth!)
return createRemote(ghApi, dbApi, auth)
return createRemote(ghApi, smartApi, dbApi, auth)
}
}

Expand Down
Loading
Loading