Skip to content

Commit

Permalink
adds test job
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan committed Jan 30, 2024
1 parent eb866a3 commit 51f86d9
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 27 deletions.
58 changes: 58 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"extends": ["@medic", "plugin:node/recommended"],
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 2020
},
"ignorePatterns": [
"**/node_modules/**"
],
"plugins": ["node"],
"rules": {
"array-bracket-newline": ["error", "consistent"],
"array-callback-return": ["error", { "allowImplicit": true }],
"arrow-spacing": ["error", { "before": true, "after": true }],
"brace-style": ["error", "1tbs"],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": ["error", "last"],
"default-param-last": "error",
"dot-location": ["error", "property"],
"dot-notation": ["error", { "allowKeywords": true }],
"func-call-spacing": ["error", "never"],
"func-style": ["error", "expression"],
"function-call-argument-newline": ["error", "consistent"],
"function-paren-newline": ["error", "consistent"],
"implicit-arrow-linebreak": ["error", "beside"],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"keyword-spacing": ["error", { "before": true, "after": true }],
"linebreak-style": ["error", "unix"],
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"new-parens": "error",
"no-alert": "error",
"no-else-return": "error",
"no-extra-bind": "error",
"no-lone-blocks": "error",
"no-nested-ternary": "error",
"no-undef-init": "error",
"no-useless-rename": "error",
"no-whitespace-before-property": "error",
"node/no-exports-assign": "error",
"rest-spread-spacing": ["error", "never"],
"semi-spacing": ["error", { "before": false, "after": true }],
"semi-style": ["error", "last"],
"template-curly-spacing": "error",
"unicode-bom": ["error", "never"]
},
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"node/no-unpublished-require": "off"
}
}
]
}
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on: [push, pull_request]

jobs:
unit:
name: Unit
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
- run: npm ci
- run: npm run test`
144 changes: 144 additions & 0 deletions package-lock.json

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

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"description": "Plugin that forces session authentication for PouchDb http adapter",
"main": "src/index.js",
"scripts": {
"test": "nyc mocha ./test/unit/*.js"
"unit": "nyc mocha ./test/unit/*.js",
"lint": "eslint .",
"test": "npm run lint && npm run unit"
},
"engines": {
"node": ">=16.12.0",
"npm": ">=8.3.1"
},
"author": "Diana Barsan",
"license": "AGPL-3.0-only",
Expand All @@ -15,6 +21,7 @@
"@medic/eslint-config": "^1.1.0",
"chai": "^4.4.1",
"eslint": "^8.56.0",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"rewire": "^7.0.0",
Expand Down
12 changes: 3 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const cookieRegex = new RegExp(`${sessionCookieName}=(.*)`);
const sessions = {};

const parseCookie = (response) => {
const cookie = response.headers && response.headers.get('set-cookie');
const cookie = response?.headers?.get('set-cookie');
if (!cookie) {
return;
}
Expand All @@ -22,12 +22,10 @@ const parseCookie = (response) => {
}

const parts = matches[1].split(';').map(item => item.trim().split('='));
const session = {
return {
token: parts[0][0],
expires: new Date(parts.find(part => part[0] === 'Expires')[1]).valueOf(),
};

return session;
};

const getExistingSession = (db) => {
Expand Down Expand Up @@ -79,12 +77,11 @@ const invalidateSession = db => {

const isExpired = (session) => {
return Date.now() > session.expires;
}
};

const extractAuth = (opts) => {
if (opts.auth) {
opts.credentials = opts.auth;
//delete opts.auth;
}

const url = new URL(opts.name);
Expand All @@ -96,9 +93,6 @@ const extractAuth = (opts) => {
username: url.username,
password: url.password
};

// url.username = url.password = '';
// opts.name = url.toString();
};

// eslint-disable-next-line func-style
Expand Down
Loading

0 comments on commit 51f86d9

Please sign in to comment.