From 298bfd156d829e0f3a5051b806318b4aab0aba51 Mon Sep 17 00:00:00 2001 From: Eleftherios Chaidemenos Date: Fri, 4 Aug 2023 17:36:03 +0300 Subject: [PATCH] Add logs --- packages/api/package.json | 2 +- .../src/time-series/time-series.service.ts | 2 ++ .../api/src/time-series/time-series.spec.ts | 23 +++++++++++++++++++ packages/api/test/app.spec.ts | 18 +++++++-------- packages/api/test/jest.json | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index e4fedb4ec..19d611769 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -34,7 +34,7 @@ "start:debug": "nest start --debug --watch", "start:prod": "node dist/src/main.js", "lint": "eslint \"{src,apps,libs,test,scripts}/**/*.{ts,js}\" --max-warnings 0", - "test": "cross-env NODE_ENV=test jest --config ./test/jest.json --silent", + "test": "cross-env NODE_ENV=test jest --config ./test/jest.json", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", diff --git a/packages/api/src/time-series/time-series.service.ts b/packages/api/src/time-series/time-series.service.ts index e586a71d2..b68ddb8ee 100644 --- a/packages/api/src/time-series/time-series.service.ts +++ b/packages/api/src/time-series/time-series.service.ts @@ -252,6 +252,7 @@ export class TimeSeriesService { const uploadResponse = await Bluebird.Promise.map( files, async ({ path, originalname, mimetype }) => { + console.log('path', path); try { const ignoredHeaders = await uploadTimeSeriesData({ user, @@ -281,6 +282,7 @@ export class TimeSeriesService { error: error.message, }; } finally { + console.log('unlinkSync path', path); // Remove file once its processing is over unlinkSync(path); } diff --git a/packages/api/src/time-series/time-series.spec.ts b/packages/api/src/time-series/time-series.spec.ts index f1693ba6d..0a4d4ddba 100644 --- a/packages/api/src/time-series/time-series.spec.ts +++ b/packages/api/src/time-series/time-series.spec.ts @@ -186,15 +186,23 @@ export const timeSeriesTests = () => { let surveyPoints: SiteSurveyPoint[]; let fistSitePointId: number; + console.log(0); + it('setups the user relations', async () => { + console.log(1); + user = await dataSource.getRepository(User).findOne({ where: { firebaseUid: siteManagerUserMock.firebaseUid as string }, select: ['id'], }); + console.log(2); + sites = await dataSource.getRepository(Site).find(); expect(sites.length).toBe(3); + console.log(3); + surveyPoints = await dataSource.getRepository(SiteSurveyPoint).find(); fistSitePointId = surveyPoints.find((x) => x.siteId === sites[0].id) ?.id as number; @@ -202,6 +210,8 @@ export const timeSeriesTests = () => { expect(fistSitePointId).toBeDefined(); expect(csvDataMock.length).toBe(30); + console.log(4); + await dataSource .getRepository(User) .createQueryBuilder('user') @@ -209,6 +219,8 @@ export const timeSeriesTests = () => { .of(user) .add(sites.slice(0, 2)); + console.log(5); + firstSiteRows = 20; }); @@ -230,6 +242,8 @@ export const timeSeriesTests = () => { return result; }); + console.log(6); + const csvString = stringify(editedData, { header: true }); mockExtractAndVerifyToken(siteManager2FirebaseUserMock); @@ -238,6 +252,8 @@ export const timeSeriesTests = () => { .attach('files', Buffer.from(csvString), 'data.csv') .set('Content-Type', 'text/csv'); + console.log(7); + expect(resp.status).toBe(201); expect( @@ -246,6 +262,8 @@ export const timeSeriesTests = () => { }); it('upload fails for wrong site id', async () => { + console.log(8); + const editedData = csvDataMock.map((row, i) => { const result = row; @@ -264,6 +282,8 @@ export const timeSeriesTests = () => { .attach('files', Buffer.from(csvString), 'data2.csv') .set('Content-Type', 'text/csv'); + console.log(9); + expect( response.body.find( (x) => x.error === `Invalid values for 'aqualink_site_id'`, @@ -272,6 +292,7 @@ export const timeSeriesTests = () => { }); it('upload fails for wrong survey point id', async () => { + console.log(10); const wrongPointId = surveyPoints.find((x) => x.id !== fistSitePointId) ?.id as number; @@ -296,6 +317,8 @@ export const timeSeriesTests = () => { .attach('files', Buffer.from(csvString), 'data2.csv') .set('Content-Type', 'text/csv'); + console.log(11); + expect( response.body.find((x) => (x.error as string).startsWith('Survey point with id'), diff --git a/packages/api/test/app.spec.ts b/packages/api/test/app.spec.ts index 180715560..cdb3f89ab 100644 --- a/packages/api/test/app.spec.ts +++ b/packages/api/test/app.spec.ts @@ -28,25 +28,25 @@ describe('AppController (e2e)', () => { expect(app).toBeDefined(); }); - describe('HealthCheck (e2e) /health-check', healthCheckTests); + // describe('HealthCheck (e2e) /health-check', healthCheckTests); - describe('User (e2e) /users', userTests); + // describe('User (e2e) /users', userTests); - describe('Site SurveyPoints (e2e) /site-survey-points', surveyPointTests); + // describe('Site SurveyPoints (e2e) /site-survey-points', surveyPointTests); - describe('Collection (e2e) /collections', collectionTests); + // describe('Collection (e2e) /collections', collectionTests); describe('Time Series (e2e) /time-series', timeSeriesTests); - describe('Region (e2e) /regions', regionTests); + // describe('Region (e2e) /regions', regionTests); - describe('Site Application {e2e) /site-applications', siteApplicationTests); + // describe('Site Application {e2e) /site-applications', siteApplicationTests); - describe('Survey (e2e) /sites/:id/surveys', surveyTests); + // describe('Survey (e2e) /sites/:id/surveys', surveyTests); - describe('Sites (e2e) /sites', siteTests); + // describe('Sites (e2e) /sites', siteTests); - describe('Sensors (e2e) /sensors', sensorTests); + // describe('Sensors (e2e) /sensors', sensorTests); afterAll(async () => { await testService.cleanUpApp(); diff --git a/packages/api/test/jest.json b/packages/api/test/jest.json index e9b702830..34c689b4e 100644 --- a/packages/api/test/jest.json +++ b/packages/api/test/jest.json @@ -2,7 +2,7 @@ "moduleFileExtensions": ["js", "json", "ts"], "rootDir": "../", "testEnvironment": "node", - "testRegex": ["app.spec.ts$", "test.ts$"], + "testRegex": ["app.spec.ts$"], "testTimeout": 120000, "verbose": true, "collectCoverage": true,