Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaschampagne committed Apr 30, 2024
1 parent 5f1f29b commit bec8532
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 39 deletions.
6 changes: 3 additions & 3 deletions desktop/src/connectors/file/file.connector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ describe("FileConnector", () => {
return SportsLibProcessor.getEvent(activityFile.location.path);
});

spyOn(fileConnector, "uploadToConnectorDebug").and.stub();

// Same for activity computing: avoid worker use
spyOn(fileConnector, "computeActivity").and.callFake(
(
Expand Down Expand Up @@ -493,7 +491,9 @@ describe("FileConnector", () => {

// Then
syncEvent$.subscribe(
() => {},
() => {
// Nothing...
},
error => {
expect(error).toBeDefined();
expect(syncEvents$NextSpy).toHaveBeenCalledWith(new StoppedSyncEvent(ConnectorType.FILE));
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/connectors/strava/strava.connector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ describe("StravaConnector", () => {
// Skip sleep to 0ms
spyOn(stravaConnector.stravaApiClient, "sleep").and.returnValue(Promise.resolve());

spyOn(stravaConnector, "uploadStravaActivityInError").and.stub();

// Avoid worker use for activity computing
computeActivitySpy = spyOn(stravaConnector, "computeActivity").and.callFake(
(
Expand Down Expand Up @@ -247,7 +245,9 @@ describe("StravaConnector", () => {

// Then
syncEvent$.pipe(filter(evt => evt.type !== SyncEventType.GENERIC)).subscribe(
() => {},
() => {
// Nothing...
},
error => {
expect(error).toBeDefined();
expect(syncPagesSpy).toBeCalledTimes(expectedSyncPagesCalls);
Expand Down
30 changes: 0 additions & 30 deletions desktop/src/connectors/strava/strava.connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,6 @@ export class StravaConnector extends BaseConnector {

syncEvents$.next(errorSyncEvent); // Notify error

// Upload activity for debug purpose
this.uploadStravaActivityInError(stravaActivity, streams, error.message);

return Promise.resolve(); // Continue to next activity
});
},
Expand Down Expand Up @@ -672,31 +669,4 @@ export class StravaConnector extends BaseConnector {
}
});
}

public uploadStravaActivityInError(stravaActivity: StravaActivity, streams: Streams, reason: string): void {
// Prepare source stravaActivity and streams
const payload = {
activity: stravaActivity,
streams: streams
};

const targetTmpPath = `${os.tmpdir()}/strava_activity_${stravaActivity.id}.json`;

fs.writeFile(targetTmpPath, JSON.stringify(payload), { flag: "w+" }, err => {
if (err) {
this.logger.error(`Unable to write strava debug file to ${targetTmpPath}. Error: ${err.message}`);
} else {
this.logger.info(`Saved strava debug data to ${targetTmpPath}`);
this.uploadActivityInError(
ConnectorType.STRAVA,
stravaActivity.type,
"json",
"elevate",
reason,
targetTmpPath,
stravaActivity.id
);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ describe("File activities integration tests", () => {
}
);

spyOn(fileConnector, "uploadToConnectorDebug").and.stub();

// Same for activity computing: avoid worker use
spyOn(fileConnector, "computeActivity").and.callFake(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe("Strava activities integration tests", () => {

spyOn(stravaConnector.athleteSnapshotResolver, "resolve").and.returnValue(athleteSnapshotModel);
spyOn(stravaConnector, "findLocalActivities").and.returnValue(Promise.resolve(null));
spyOn(stravaConnector, "uploadToConnectorDebug").and.stub();

syncEventsSpy = spyOn(syncEvents$, "next").and.callThrough();

Expand Down

0 comments on commit bec8532

Please sign in to comment.