Skip to content

Commit

Permalink
feat(middy2): middy v2 version (#34)
Browse files Browse the repository at this point in the history
- updated deps
- stopped breaking the middleware chain
- updated the tests
- bump version to 2.0.0
  • Loading branch information
domeq authored Jul 27, 2021
1 parent 252747a commit 7f92520
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 74 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ const corsMiddleware = (opts) => ({
},
handler.response
);

return handler;
},
});

Expand Down
98 changes: 40 additions & 58 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,15 @@ test('Adds CORS headers on error from disallowed origin', async () => {
},
{}
)
).rejects.toEqual(
expect.objectContaining({
response: {
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
},
})
);
).resolves.toMatchObject({
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
});
});

test('Adds CORS headers on error from allowed origin', async () => {
Expand Down Expand Up @@ -216,20 +212,16 @@ test('Adds CORS headers on error from allowed origin', async () => {
},
{}
)
).rejects.toEqual(
expect.objectContaining({
response: {
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
},
})
);
).resolves.toMatchObject({
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
});
});

test('Adds CORS headers on error when all origins allowed', async () => {
Expand Down Expand Up @@ -257,20 +249,16 @@ test('Adds CORS headers on error when all origins allowed', async () => {
},
{}
)
).rejects.toEqual(
expect.objectContaining({
response: {
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
},
})
);
).resolves.toMatchObject({
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
},
});
});

test('Keep headers already present in the response on error from disallowed origin', async () => {
Expand All @@ -286,8 +274,6 @@ test('Keep headers already present in the response on error from disallowed orig
someHeader: 'someValue',
},
};

return true;
});

handler.use(
Expand All @@ -310,19 +296,15 @@ test('Keep headers already present in the response on error from disallowed orig
},
{}
)
).rejects.toEqual(
expect.objectContaining({
response: {
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
someHeader: 'someValue',
},
},
})
);
).resolves.toMatchObject({
headers: {
'access-control-allow-credentials': true,
'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For',
'access-control-allow-methods': 'GET, POST',
'access-control-allow-origin': 'https://www.tek.no',
'access-control-expose-headers': 'x-my-header',
'access-control-max-age': 2628000,
someHeader: 'someValue',
},
});
});
24 changes: 13 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@schibsted/middy-cors",
"version": "0.3.0",
"version": "2.0.0",
"description": "Middy middleware for adding CORS headers to success response and errors",
"main": "index.js",
"engines": {
Expand Down Expand Up @@ -47,7 +47,7 @@
},
"homepage": "https://github.com/schibsted/middy-cors#readme",
"devDependencies": {
"@middy/core": "^1.4.0",
"@middy/core": "^2.4.3",
"babel-eslint": "^10.1.0",
"eslint": "^7.11.0",
"eslint-config-airbnb-base": "^14.2.0",
Expand All @@ -66,6 +66,6 @@
"ramda": "^0.27.1"
},
"peerDependencies": {
"@middy/core": ">=1.0.0"
"@middy/core": ">=2.0.0"
}
}

0 comments on commit 7f92520

Please sign in to comment.