Skip to content

Commit

Permalink
fix: add empty check for batch upserts
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuartu committed Sep 23, 2024
1 parent cf2e569 commit 9735ac7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand All @@ -587,10 +585,8 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
await controller.syncInternalAccountsWithUserStorage();

mockAPI.mockEndpointGetUserStorage.done();
mockAPI.mockEndpointBatchUpsertUserStorage.done();

expect(mockAPI.mockEndpointGetUserStorage.isDone()).toBe(true);
expect(mockAPI.mockEndpointBatchUpsertUserStorage.isDone()).toBe(true);

expect(messengerMocks.mockKeyringAddNewAccount).toHaveBeenCalledTimes(
MOCK_USER_STORAGE_ACCOUNTS.SAME_AS_INTERNAL_ALL.length -
Expand Down Expand Up @@ -621,8 +617,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -730,8 +724,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -860,8 +852,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -905,8 +895,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -984,8 +972,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -1039,8 +1025,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -1084,8 +1068,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
await mockUserStorageAccountsResponse(),
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down Expand Up @@ -1132,8 +1114,6 @@ describe('user-storage/user-storage-controller - syncInternalAccountsWithUserSto
'accounts',
mockGetEntriesResponse,
),
mockEndpointBatchUpsertUserStorage:
mockEndpointBatchUpsertUserStorage('accounts'),
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export async function batchUpsertUserStorage(
data: [UserStoragePathWithKeyOnly, string][],
opts: UserStorageBatchUpsertOptions,
): Promise<void> {
if (!data.length) {
return;
}

const { bearerToken, path, storageKey, nativeScryptCrypto } = opts;

const encryptedData = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('User Storage', () => {
});

await expect(
userStorage.batchSetItems('notifications', []),
userStorage.batchSetItems('notifications', [['key', 'value']]),
).rejects.toThrow(UserStorageError);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/profile-sync-controller/src/sdk/user-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export class UserStorage {
data: [UserStoragePathWithKeyOnly, string][],
): Promise<void> {
try {
if (!data.length) {
return;
}

const headers = await this.#getAuthorizationHeader();
const storageKey = await this.getStorageKey();

Expand Down

0 comments on commit 9735ac7

Please sign in to comment.