-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: Avoid trigger last execution "unknown" while the connector is still running #1515
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ import { | |
launchTrigger | ||
} from '../connections/triggers' | ||
import CozyRealtime from 'cozy-realtime' | ||
import KonnectorJobWatcher from './konnector/KonnectorJobWatcher' | ||
import KonnectorJobWatcher, { watchKonnectorJob } from './konnector/KonnectorJobWatcher' | ||
import { konnectorPolicy as biKonnectorPolicy } from '../services/budget-insight' | ||
import fixtures from '../../test/fixtures' | ||
import sentryHub from '../sentry' | ||
import { Q } from 'cozy-client' | ||
|
||
jest.mock('./konnector/KonnectorJobWatcher') | ||
jest.mock('../sentry', () => { | ||
const mockScope = { | ||
setTag: jest.fn() | ||
|
@@ -116,6 +117,17 @@ describe('ConnectionFlow', () => { | |
const isSubmitting = flow => { | ||
return flow.getState().running === true | ||
} | ||
beforeAll(() => { | ||
watchKonnectorJob.mockReturnValue({on: () => ({})}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should render as submitting when there is no account', async () => { | ||
const { flow } = setup() | ||
|
@@ -213,6 +225,10 @@ describe('ConnectionFlow', () => { | |
userCredentials: { | ||
login: 'foo', | ||
password: 'bar' | ||
}, | ||
account: { | ||
login: 'old', | ||
password: 'old' | ||
} | ||
}) | ||
|
||
|
@@ -314,6 +330,7 @@ describe('ConnectionFlow', () => { | |
describe('ensureTriggerAndLaunch', () => { | ||
beforeAll(() => { | ||
jest.spyOn(cronHelpers, 'fromFrequency').mockReturnValue('0 0 0 * * 0') | ||
watchKonnectorJob.mockReturnValue({on: () => ({})}) | ||
}) | ||
|
||
afterEach(() => { | ||
|
@@ -481,6 +498,24 @@ describe('ConnectionFlow', () => { | |
delete window.cozy | ||
delete window.ReactNativeWebView | ||
}) | ||
|
||
describe('contructor', () => { | ||
doubleface marked this conversation as resolved.
Show resolved
Hide resolved
|
||
beforeAll(() => { | ||
watchKonnectorJob.mockReturnValue({on: () => ({})}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
afterAll(() => { | ||
jest.restoreAllMocks() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the point to use a clearAllMocks before restoreAllMocks: https://jestjs.io/docs/mock-function-api#mockfnmockrestore I read here that mockRestore does everything that mockReset does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i recommend to remove clearAllMocks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to remove restoreAllMocks in this case. ClearAllMocks will erase the history of calls between test which is what I want in the first place. And removing clearAllMocks makes the tests fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, then. ps: I need to understand one day why mocks are not reset by default. 🤯 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
}) | ||
it('should watch a running trigger', () => { | ||
setup({trigger: fixtures.runningTrigger}) | ||
expect(watchKonnectorJob).toHaveBeenCalledWith(expect.any(Object), {_id: 'runningjobid'}, {autoSuccessTimer: false}) | ||
}) | ||
}) | ||
}) | ||
|
||
// it should have running false on trigger updates | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,11 @@ export class KonnectorJobWatcher { | |
this.emit('error', new KonnectorJobError(error)) | ||
} | ||
|
||
handleLoginSuccess() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't we test that part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would need to be an integration test. I think there is no point to add a unit test here. |
||
logger.info(`KonnectorJobWatcher: login success`) | ||
this.disableSuccessTimer() | ||
} | ||
|
||
handleSuccess() { | ||
logger.info(`KonnectorJobWatcher: Job has succeeded`) | ||
this.disableSuccessTimer() | ||
|
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.
what is the point to use a clearAllMocks before restoreAllMocks:
https://jestjs.io/docs/mock-function-api#mockfnmockrestore
I read here that mockRestore does everything that mockReset does
And mockReset does everything that mockClear deos
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.
nit: i recommend to remove clearAllMocks