-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
144 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ jspm_packages | |
.npm | ||
|
||
.deno | ||
.deno-cache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
import { assertEquals, assertObjectMatch } from 'https://deno.land/[email protected]/assert/mod.ts'; | ||
import { beforeEach, describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts'; | ||
import { spy } from "https://deno.land/[email protected]/testing/mock.ts"; | ||
import { spy } from 'https://deno.land/[email protected]/testing/mock.ts'; | ||
|
||
import { AppObjectRegistry } from '../../AppObjectRegistry.ts'; | ||
import videoconfHandler from '../videoconference-handler.ts'; | ||
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts"; | ||
import { JsonRpcError } from "jsonrpc-lite"; | ||
import { assertInstanceOf } from 'https://deno.land/[email protected]/assert/assert_instance_of.ts'; | ||
import { JsonRpcError } from 'jsonrpc-lite'; | ||
|
||
describe('handlers > videoconference', () => { | ||
// deno-lint-ignore no-unused-vars | ||
|
@@ -16,15 +16,18 @@ describe('handlers > videoconference', () => { | |
// deno-lint-ignore no-unused-vars | ||
const mockMethodWithTwoParam = (call: any, user: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok two'); | ||
// deno-lint-ignore no-unused-vars | ||
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok three'); | ||
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> => | ||
Promise.resolve('ok three'); | ||
const mockProvider = { | ||
empty: mockMethodWithoutParam, | ||
one: mockMethodWithOneParam, | ||
two: mockMethodWithTwoParam, | ||
three: mockMethodWithThreeParam, | ||
notAFunction: true, | ||
error: () => { throw new Error('Method execution error example') } | ||
} | ||
error: () => { | ||
throw new Error('Method execution error example'); | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
AppObjectRegistry.clear(); | ||
|
@@ -36,9 +39,9 @@ describe('handlers > videoconference', () => { | |
|
||
const result = await videoconfHandler('videoconference:test-provider:empty', []); | ||
|
||
assertEquals(result, 'ok none') | ||
assertEquals(result, 'ok none'); | ||
assertEquals(_spy.calls[0].args.length, 4); | ||
|
||
_spy.restore(); | ||
}); | ||
|
||
|
@@ -47,7 +50,7 @@ describe('handlers > videoconference', () => { | |
|
||
const result = await videoconfHandler('videoconference:test-provider:one', ['call']); | ||
|
||
assertEquals(result, 'ok one') | ||
assertEquals(result, 'ok one'); | ||
assertEquals(_spy.calls[0].args.length, 5); | ||
assertEquals(_spy.calls[0].args[0], 'call'); | ||
|
||
|
@@ -59,7 +62,7 @@ describe('handlers > videoconference', () => { | |
|
||
const result = await videoconfHandler('videoconference:test-provider:two', ['call', 'user']); | ||
|
||
assertEquals(result, 'ok two') | ||
assertEquals(result, 'ok two'); | ||
assertEquals(_spy.calls[0].args.length, 6); | ||
assertEquals(_spy.calls[0].args[0], 'call'); | ||
assertEquals(_spy.calls[0].args[1], 'user'); | ||
|
@@ -72,7 +75,7 @@ describe('handlers > videoconference', () => { | |
|
||
const result = await videoconfHandler('videoconference:test-provider:three', ['call', 'user', 'options']); | ||
|
||
assertEquals(result, 'ok three') | ||
assertEquals(result, 'ok three'); | ||
assertEquals(_spy.calls[0].args.length, 7); | ||
assertEquals(_spy.calls[0].args[0], 'call'); | ||
assertEquals(_spy.calls[0].args[1], 'user'); | ||
|
@@ -84,34 +87,36 @@ describe('handlers > videoconference', () => { | |
it('correctly handles an error on execution of a videoconf method', async () => { | ||
const result = await videoconfHandler('videoconference:test-provider:error', []); | ||
|
||
assertInstanceOf(result, JsonRpcError) | ||
assertInstanceOf(result, JsonRpcError); | ||
assertObjectMatch(result, { | ||
message: 'Method execution error example', | ||
code: -32000 | ||
}) | ||
}) | ||
code: -32000, | ||
}); | ||
}); | ||
|
||
it('correctly handles an error when provider is not found', async () => { | ||
const providerName = 'error-provider' | ||
const providerName = 'error-provider'; | ||
const result = await videoconfHandler(`videoconference:${providerName}:method`, []); | ||
|
||
assertInstanceOf(result, JsonRpcError) | ||
assertInstanceOf(result, JsonRpcError); | ||
assertObjectMatch(result, { | ||
message: `Provider ${providerName} not found`, | ||
code: -32000 | ||
}) | ||
}) | ||
code: -32000, | ||
}); | ||
}); | ||
|
||
it('correctly handles an error if method is not a function of provider', async () => { | ||
const methodName = 'notAFunction' | ||
const providerName = 'test-provider' | ||
const methodName = 'notAFunction'; | ||
const providerName = 'test-provider'; | ||
const result = await videoconfHandler(`videoconference:${providerName}:${methodName}`, []); | ||
|
||
assertInstanceOf(result, JsonRpcError) | ||
assertInstanceOf(result, JsonRpcError); | ||
assertObjectMatch(result, { | ||
message: `Method ${methodName} not found on provider ${providerName}`, | ||
code: -32000 | ||
}) | ||
}) | ||
|
||
message: 'Method not found', | ||
code: -32601, | ||
data: { | ||
message: `Method ${methodName} not found on provider ${providerName}`, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const childProcess = require('child_process'); | ||
const path = require('path'); | ||
|
||
// Find executable installed by deno-bin | ||
const executablePath = path.join(require.resolve('deno-bin'), '..', 'bin', 'deno'); | ||
|
||
const rootPath = path.join(__dirname, '..'); | ||
const DENO_DIR = path.join(rootPath, '.deno-cache'); | ||
|
||
childProcess.spawnSync(executablePath, ['cache', 'main.ts'], { | ||
cwd: path.join(rootPath, 'deno-runtime'), | ||
env: { | ||
DENO_DIR, | ||
}, | ||
stdio: 'inherit', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.