From ef264df876c38bade196e12572b8b7fb3dc4eefc Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Fri, 16 Feb 2024 20:09:03 +0100 Subject: [PATCH] feat: Add app and device info in fileLogger's email body --- src/app/domain/logger/fileLogger.spec.ts | 10 ++++++---- src/app/domain/logger/fileLogger.ts | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/app/domain/logger/fileLogger.spec.ts b/src/app/domain/logger/fileLogger.spec.ts index 5d77e1f0d..97ffc4c34 100644 --- a/src/app/domain/logger/fileLogger.spec.ts +++ b/src/app/domain/logger/fileLogger.spec.ts @@ -85,10 +85,12 @@ describe('fileLogger', () => { await sendLogs(client) expect(Alert.alert).not.toHaveBeenCalled() - expect(sendLogFilesByEmailSpy).toHaveBeenCalledWith({ - subject: 'Log file for ', - to: 'somemail@somedomain.com' - }) + expect(sendLogFilesByEmailSpy).toHaveBeenCalledWith( + expect.objectContaining({ + subject: 'Log file for ', + to: 'somemail@somedomain.com' + }) + ) }) it('should do nothing and display alert if logs are disabled', async () => { diff --git a/src/app/domain/logger/fileLogger.ts b/src/app/domain/logger/fileLogger.ts index b7b5e834e..ab0383370 100644 --- a/src/app/domain/logger/fileLogger.ts +++ b/src/app/domain/logger/fileLogger.ts @@ -1,5 +1,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage' import { Alert } from 'react-native' +import DeviceInfo from 'react-native-device-info' import { FileLogger, LogLevel } from 'react-native-file-logger' import type CozyClient from 'cozy-client' @@ -49,7 +50,8 @@ export const sendLogs = async (client?: CozyClient): Promise => { log.info('Start email intent') const emailResult = await FileLogger.sendLogFilesByEmail({ to: supportEmail, - subject: subject + subject: subject, + body: buildMessageBody() }) log.info('Did finish email intent:', emailResult) await hideSplashScreen(splashScreens.SEND_LOG_EMAIL) @@ -94,3 +96,19 @@ const areLogsEnabledInAsyncStorage = async (): Promise => { return logsEnabled === '1' } + +const buildMessageBody = (): string => { + const appVersion = DeviceInfo.getVersion() + const appBuild = DeviceInfo.getBuildNumber() + const bundle = DeviceInfo.getBundleId() + const deviceBrand = DeviceInfo.getBrand() + const deviceModel = DeviceInfo.getModel() + const os = DeviceInfo.getSystemName() + const version = DeviceInfo.getSystemVersion() + + const appInfo = `App info: ${appVersion} (${appBuild})` + const bundleInfo = `App bundle: ${bundle}` + const deviceInfo = `Device info: ${deviceBrand} ${deviceModel} ${os} ${version}` + + return `${appInfo}\n${bundleInfo}\n${deviceInfo}` +}