New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Organize the source files in the OAuth package #1430
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments for reviewers
@@ -33,7 +33,7 @@ | |||
"build:clean": "shx rm -rf ./dist ./coverage ./.nyc_output", | |||
"lint": "eslint --ext .ts src", | |||
"test": "npm run lint && npm run test:mocha", | |||
"test:mocha": "nyc mocha --config .mocharc.json src/*.spec.js", | |||
"test:mocha": "nyc mocha --config .mocharc.json src/*.spec.js src/**/*.spec.js src/*.spec.ts src/**/*.spec.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I've added more tests including the ones in TypeScript, this change is necessary for running all
@@ -61,7 +63,7 @@ | |||
"eslint-plugin-node": "^11.1.0", | |||
"mocha": "^9.1.0", | |||
"nop": "^1.0.0", | |||
"nyc": "^14.1.1", | |||
"nyc": "^15.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for fixing npm audit
warnings
import { MissingStateError } from './errors'; | ||
|
||
describe('CallbackOptions', async () => { | ||
it('should have success and failure', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are not so great but it's better than nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, only about ~62% of branches are tested in this package, so definitely room for improvement!
@@ -631,232 +630,4 @@ describe('OAuth', async () => { | |||
assert.equal(fakeStateStore.verifyStateParam.callCount, 0); | |||
}); | |||
}); | |||
|
|||
describe('MemoryInstallationStore', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These deleted tests are moved to more relevant files.
// This is intentionally structurally identical to AuthorizeResult from App | ||
// It is redefined so that this class remains loosely coupled to the rest | ||
// of Bolt. | ||
export interface AuthorizeResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to have dedicated files for these interface. However, I didn't do so at this moment because these are used only in InstallProvider
. If we want to make it more granular, we can do so in future changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, these are exported in index.ts
as with before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revisited this and I came to think that AuthorizeResult
should be authorize-result.ts
as external code relies on this interface.
assert.match(newLogger.name, /test-logger-name:\d+/); | ||
assert.equal(newLogger.getLevel(), LogLevel.DEBUG); | ||
}); | ||
it('should modify the passed logger', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this clear, I've added this test
isEnterpriseInstall: false, | ||
} | ||
|
||
// TODO: valid tests with org-wide installations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add more tests for org-wide installations and token rotation use cases
@@ -30,6 +30,7 @@ | |||
], | |||
"exclude": [ | |||
"src/**/*.spec.js", | |||
"src/**/*.spec.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few TS tests. They should be excluded in the package file. I've verified if this works by running npm pack
.
}); | ||
|
||
it('should store the latest installation', async () => { | ||
const installationStore = new FileInstallationStore({ baseDir: './tmp' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the base directory for outputs - previously the tests used to generate directories in current dir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary as a change but another option is to use os.tmpDir()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice! will update this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Ran it locally. Also much easier now to figure out where the missing code coverage is (via npm it && nyc report --reporter=text
) - thanks a lot for doing this.
import { MissingStateError } from './errors'; | ||
|
||
describe('CallbackOptions', async () => { | ||
it('should have success and failure', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, only about ~62% of branches are tested in this package, so definitely room for improvement!
}); | ||
|
||
it('should store the latest installation', async () => { | ||
const installationStore = new FileInstallationStore({ baseDir: './tmp' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary as a change but another option is to use os.tmpDir()
512f2b1
to
48d1c61
Compare
Thanks for your review @filmaj ! |
Summary
As a preparation for my forthcoming pull requests, this patch splits the big
index.ts
file into smaller pieces of code. This change improves the maintainability of both the main code and test code.The changes in this PR are:
index.ts
ClearStateState
from the file to./src/state-stores/clear-state-store.ts
./src/state-stores/interface.ts
InstallationStore
from the file to./src/stores/interface.ts
./src/index.spec.js
to relevant spec filesInstallProvider
,CallbackOptions
,InstallURLOptions
,InstallProviderOptions
,Installation
,InstallationQuery
to dedicated filessrc/index.ts
are fully backward-compatiblelogger.ts
I will rebase #1425 after merging this PR.
Requirements (place an
x
in each[ ]
)