Skip to content

Commit c549f8b

Browse files
author
Erika Perugachi
authored
Merge pull request #1174 from JulianAdams4/fixes
Some Fixes
2 parents e5c6624 + 9c84a09 commit c549f8b

File tree

8 files changed

+175
-69
lines changed

8 files changed

+175
-69
lines changed

electron_app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"electron-updater": "^3.0.3",
147147
"electron-window-state": "^4.1.1",
148148
"getos": "^3.1.1",
149-
"knex": "0.15.2",
149+
"knex": "0.17.6",
150150
"line-by-line": "^0.1.6",
151151
"moment": "^2.22.2",
152152
"os-locale": "^3.0.1",

electron_app/src/DBManager.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ const deleteEmailContactByEmailId = (emailId, trx) => {
235235
/* EmailLabel
236236
----------------------------- */
237237
const createEmailLabel = (emailLabels, prevTrx) => {
238-
const transaction = prevTrx ? fn => fn(prevTrx) : db.transaction;
239-
return transaction(async trx => {
238+
const createOrUseTrx = (oldTrx, callback) => {
239+
if (oldTrx) return callback(oldTrx);
240+
return db.transaction(newTrx => callback(newTrx));
241+
};
242+
return createOrUseTrx(prevTrx, async trx => {
240243
const toInsert = await filterEmailLabelIfNotStore(emailLabels, trx);
241244
if (toInsert.length) {
242245
await filterEmailLabelTrashToUpdateEmail(toInsert, 'create', trx);
@@ -252,8 +255,11 @@ const deleteEmailLabel = ({ emailIds, labelIds }, prevTrx) => {
252255
labelId: labelIds[0]
253256
};
254257
});
255-
const transaction = prevTrx ? fn => fn(prevTrx) : db.transaction;
256-
return transaction(async trx => {
258+
const createOrUseTrx = (oldTrx, callback) => {
259+
if (oldTrx) return callback(oldTrx);
260+
return db.transaction(newTrx => callback(newTrx));
261+
};
262+
return createOrUseTrx(prevTrx, async trx => {
257263
await filterEmailLabelTrashToUpdateEmail(emailLabels, 'delete', trx);
258264
return await trx
259265
.table(Table.EMAIL_LABEL)

electron_app/src/__integrations__/Email.integration.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,57 @@ describe('Store relation data to EmailLabel Table: ', () => {
319319
const response = await DBManager.createEmailLabel(emailLabelDraft);
320320
expect(response).toBeUndefined();
321321
});
322+
323+
it('Should Add and Remove emailLabel relation to database', async () => {
324+
const emailUpdateLabels = {
325+
email: {
326+
threadId: 'threadK',
327+
key: '12',
328+
s3Key: 's3KeyK',
329+
subject: 'Greetings',
330+
content: '<p>Hello there</p>',
331+
preview: 'Hello there',
332+
date: '2013-10-07 08:23:20.120',
333+
status: 1,
334+
unread: false,
335+
secure: true,
336+
isMuted: false,
337+
messageId: 'messageIdK',
338+
fromAddress: 'User me <[email protected]>'
339+
},
340+
recipients: {
341+
from: ['User me <[email protected]>'],
342+
343+
},
344+
labels: [3, 7]
345+
};
346+
await DBManager.createEmail(emailUpdateLabels);
347+
const [email] = await DBManager.getEmailByKey(emailUpdateLabels.email.key);
348+
// Add
349+
const emailLabelToAdd = [
350+
{ emailId: email.id, labelId: systemLabels.starred.id }
351+
];
352+
const [addResponse] = await DBManager.createEmailLabel(emailLabelToAdd);
353+
expect(addResponse).toEqual(expect.any(Number));
354+
// Remove
355+
await DBManager.deleteEmailLabel({
356+
emailIds: [email.id],
357+
labelIds: [systemLabels.starred.id]
358+
});
359+
// Check if exists
360+
let existsRelation = false;
361+
const remainingEmailLabels = await DBManager.getEmailLabelsByEmailId(
362+
email.id
363+
);
364+
for (const remainingLabel of remainingEmailLabels) {
365+
const { labelId } = remainingLabel;
366+
if (labelId === systemLabels.starred.id) {
367+
existsRelation = true;
368+
break;
369+
}
370+
}
371+
expect(existsRelation).toBe(false);
372+
});
322373
});
323374

324375
describe('Load data emails from Email Table:', () => {

electron_app/src/globalManager.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
const packageData = require('./../package.json');
2-
const allInstallerTypes = require('./../installerResources/installerTypes.json');
1+
const { INSTALLER_TYPE } = require('./utils/const');
32
const { getDeviceType } = require('./utils/osUtils');
4-
const currrentInstallerType = packageData.criptextInstallerType;
3+
const allInstallerTypes = require('./../installerResources/installerTypes.json');
54

65
global.composerData = {};
76
global.emailToEdit = {};
8-
global.isMAS = currrentInstallerType === allInstallerTypes.mac.store;
7+
global.isMAS = INSTALLER_TYPE === allInstallerTypes.mac.store;
98
global.loadingData = {};
109
global.modalData = {};
1110
global.temporalAccount = {};
1211
global.windowsEventsDisabled = false;
1312
global.internetConnection;
14-
global.isWindowsStore =
15-
currrentInstallerType === allInstallerTypes.windows.store;
16-
global.deviceType = getDeviceType(currrentInstallerType, allInstallerTypes);
13+
global.isWindowsStore = INSTALLER_TYPE === allInstallerTypes.windows.store;
14+
global.deviceType = getDeviceType(INSTALLER_TYPE, allInstallerTypes);
1715
global.pendingRestore = false;
1816

1917
/* Composer

electron_app/src/nucleusManager.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
const { APP_VERSION, NUCLEUS_ID } = require('./utils/const');
1+
const { APP_VERSION, NUCLEUS_ID, INSTALLER_TYPE } = require('./utils/const');
22
const myAccount = require('./Account');
33
let Nucleus;
44

55
const initNucleus = ({ userId }) => {
66
const data = {
77
onlyMainProcess: true,
88
userId: userId || 'unknown',
9-
version: APP_VERSION
9+
version: APP_VERSION,
10+
installerType: INSTALLER_TYPE
1011
};
1112
Nucleus = require('electron-nucleus')(NUCLEUS_ID, data);
1213
};

electron_app/src/utils/const.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* process */
22
require('dotenv').config();
3-
const { version, nucleusId } = require('./../../package.json');
3+
const {
4+
version,
5+
nucleusId,
6+
criptextInstallerType
7+
} = require('./../../package.json');
48

59
const API_CLIENT_VERSION = '9.0.0';
610
const LINK_DEVICES_FILE_VERSION = '5';
@@ -32,5 +36,6 @@ module.exports = {
3236
APP_VERSION: isDevelopment ? '0.0.0' : version,
3337
NUCLEUS_ID: isDevelopment
3438
? process.env.DEV_NUCLEUS_ID
35-
: process.env.PROD_NUCLEUS_ID || nucleusId
39+
: process.env.PROD_NUCLEUS_ID || nucleusId,
40+
INSTALLER_TYPE: criptextInstallerType
3641
};

0 commit comments

Comments
 (0)