-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure Nammatham v2 is testable (#106)
- Loading branch information
Showing
42 changed files
with
1,300 additions
and
702 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'perfectionist', 'unused-imports'], | ||
root: true, | ||
ignorePatterns: ['**.test.ts'], | ||
rules: { | ||
/** | ||
* Unused import and vars: | ||
* https://github.com/sweepline/eslint-plugin-unused-imports | ||
*/ | ||
'unused-imports/no-unused-imports': 'error', | ||
'@typescript-eslint/consistent-type-imports': 'error', | ||
/** | ||
* For config: https://eslint-plugin-perfectionist.azat.io/rules/sort-imports | ||
*/ | ||
'perfectionist/sort-imports': [ | ||
'error', | ||
{ | ||
type: 'line-length', | ||
order: 'asc', | ||
groups: [ | ||
'type', | ||
['builtin', 'external'], | ||
'internal-type', | ||
'internal', | ||
['parent-type', 'sibling-type', 'index-type'], | ||
['parent', 'sibling', 'index'], | ||
'side-effect', | ||
'style', | ||
'object', | ||
'unknown', | ||
], | ||
'newlines-between': 'always', | ||
'internal-pattern': ['@/nammatham/**'], | ||
}, | ||
], | ||
}, | ||
}; |
This file was deleted.
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
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,20 @@ | ||
import { expect, test } from 'vitest'; | ||
import { AzureFunctionsAdapter } from './adapter'; | ||
import { AzureFunctionsTrigger } from './trigger'; | ||
import { NammathamApp } from '@nammatham/core'; | ||
import { AzureFunctionsHandlerResolver } from './handler-resolver'; | ||
|
||
test(`${AzureFunctionsAdapter.name} should be created correctly`, async () => { | ||
// Arrange | ||
const adapter = new AzureFunctionsAdapter(); | ||
// Act | ||
const app = adapter.createApp(); | ||
const func = adapter.createTrigger(); | ||
|
||
// Assert | ||
expect(func).toBeInstanceOf(AzureFunctionsTrigger); | ||
expect(app).toBeInstanceOf(NammathamApp); | ||
expect(app.runtime === 'azure-functions').toBe(true); | ||
expect(app.isDevelopment).toBe(false); | ||
expect(app.handlerResolver).toBeInstanceOf(AzureFunctionsHandlerResolver); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect, test } from 'vitest'; | ||
import { AzureFunctionsHandler } from './handler'; | ||
import { InvocationContext } from '@azure/functions'; | ||
test(`${AzureFunctionsHandler.name}.handler should be invoked correctly`, async () => { | ||
// Arrange | ||
const handler = new AzureFunctionsHandler( | ||
'test', | ||
{ | ||
extraInputs: [], | ||
extraOutputs: [], | ||
endpointOption: { | ||
type: 'http', | ||
route: 'test', | ||
methods: ['GET'], | ||
}, | ||
}, | ||
() => '' | ||
); | ||
|
||
// Act | ||
const endpoint = handler.handler(() => 'handlerResult'); | ||
const result = endpoint.invokeHandler({}, new InvocationContext()); | ||
|
||
// Assert | ||
expect(result).toBe('handlerResult'); | ||
// NOTE: invokeHandler should test end-to-end | ||
expect(endpoint.invokeHandler).toBeInstanceOf(Function); | ||
// NOTE: registerFunc should test end-to-end | ||
expect(endpoint.registerFunc).toBeInstanceOf(Function); | ||
|
||
expect(handler).toBeInstanceOf(AzureFunctionsHandler); | ||
expect(endpoint.endpointOption?.type).toBe('http'); | ||
expect(endpoint.endpointOption?.route).toBe('test'); | ||
expect(endpoint.endpointOption?.methods).toEqual(['GET']); | ||
expect(endpoint.type).toBe('azure-functions'); | ||
expect(endpoint.name).toBe('test'); | ||
}); |
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,37 @@ | ||
import { expect, test } from 'vitest'; | ||
import { HttpRequest } from './HttpRequest'; | ||
import httpMocks from 'node-mocks-http'; | ||
import exp from 'constants'; | ||
|
||
test('Test HttpRequest', () => { | ||
// Arrange | ||
const req = httpMocks.createRequest({ | ||
method: 'GET', | ||
protocol: 'https', | ||
// get: (key: string) => 'localhost', | ||
url: '/api/test', | ||
query: { | ||
a: '1', | ||
b: '2', | ||
}, | ||
headers: { | ||
x: '1', | ||
y: '2', | ||
}, | ||
}); | ||
|
||
// Act | ||
const result = new HttpRequest(req); | ||
|
||
// Assert | ||
expect(result.method).toBe('GET'); | ||
expect(result.url).toBe('https://undefined/api/test'); | ||
expect(result.query.get('a')).toBe('1'); | ||
expect(result.query.get('b')).toBe('2'); | ||
expect(result.headers.get('x')).toBe('1'); | ||
expect(result.headers.get('y')).toBe('2'); | ||
expect(result.body).toBe(null); | ||
expect(result.params).toStrictEqual({}); | ||
expect(result.user).toBe(null); | ||
expect(result.bodyUsed).toBe(false); | ||
}); |
Oops, something went wrong.