Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

Commit

Permalink
test: extend tests for cli and auth-inmemory
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdumper committed Mar 26, 2019
1 parent f3d9b32 commit 3591693
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/emeralt-auth-inmemory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"access": "public"
},
"scripts": {
"test": "ava ../../test/auth.test.ts",
"test": "ava ../../test/auth.test.ts && ava ./test/*.test.ts",
"build": "gemcart build"
},
"devDependencies": {
Expand Down
45 changes: 45 additions & 0 deletions packages/emeralt-auth-inmemory/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { test } from '../../../test/utils'
import { EmeraltAuthInMemory } from '../src'

test<typeof EmeraltAuthInMemory>('provide users', async (t, authc) => {
// @ts-ignore
const auth = await authc({
users: { tester: 'tester' },
})({})

t.true(auth.comparePassword('tester', 'tester'))
t.false(auth.comparePassword('tester', 'wrong'))
})

test<typeof EmeraltAuthInMemory>('canUser', async (t, authc) => {
// @ts-ignore
const auth = await authc({
users: { tester: 'tester-pass' },
})(
{},
{
// @ts-ignore
getMetadata: () => ({
_owner: 'tester',
}),
},
)

t.true(await auth.canUser('tester', 'get', 'some-package'))
t.true(await auth.canUser('tester', 'publish', 'some-package'))

// @ts-ignore
const auth2 = await authc({
users: { tester: 'tester-pass' },
})(
{},
{
// @ts-ignore
getMetadata: () => ({
_owner: 'other_user', // important
}),
},
)

t.false(await auth2.canUser('tester', 'publish', 'some-package'))
})
16 changes: 15 additions & 1 deletion packages/emeralt-cli/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fork } from 'child_process'

const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t))

test.serial('start server', async (t) => {
test.serial('start built emeralt', async (t) => {
const server = fork('build/index.js')

await sleep(1000)
Expand All @@ -17,3 +17,17 @@ test.serial('start server', async (t) => {

t.pass()
})

test.serial('start emeralt', async (t) => {
require('../src/index')

await sleep(1000)

await supertest('http://localhost:8080')
.get('/-/ping')
.expect(200)

// server.kill('SIGTERM')

t.pass()
})

0 comments on commit 3591693

Please sign in to comment.