Skip to content

Commit

Permalink
Fix typo and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hparra committed Oct 16, 2024
1 parent e4b15cf commit 8cc970b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/handlers/unkown.js → src/handlers/unknown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export default function unkownHandler() {

export default function unknownHandler() {
const body = JSON.stringify({ message: 'Unknown method. Please see: https://docs.da.live for more information.' });
return { body, status: 501 };
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import headHandler from './handlers/head.js';
import getHandler from './handlers/get.js';
import postHandler from './handlers/post.js';
import deleteHandler from './handlers/delete.js';
import unkownHandler from './handlers/unkown.js';
import unknownHandler from './handlers/unknown.js';

export default {
async fetch(req, env) {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
respObj = await deleteHandler({ req, env, daCtx });
break;
default:
respObj = unkownHandler();
respObj = unknownHandler();
}

return daResp(respObj);
Expand Down
10 changes: 10 additions & 0 deletions test/handlers/unknown.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert';
import unknownHandler from '../../src/handlers/unknown.js';

describe('unknownHandler', () => {
it('should return unknown response', async () => {
const result = await unknownHandler({});
assert.strictEqual(result.status, 501);
assert.strictEqual(result.body.includes('Unknown method'), true);
});
});
18 changes: 18 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'assert';
import handler from '../src/index.js';

describe('fetch', () => {
it('should be callable', () => {
assert(handler.fetch);
});

it('should return a response object for options', async () => {
const resp = await handler.fetch({ method: 'OPTIONS' }, {});
assert.strictEqual(resp.status, 204);
});

it('should return a response object for unknown', async () => {
const resp = await handler.fetch({ url: 'https://www.example.com', method: 'BLAH' }, {});
assert.strictEqual(resp.status, 501);
});
});

0 comments on commit 8cc970b

Please sign in to comment.