mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
parent
ac7165461a
commit
19f0b667b1
@ -114,6 +114,9 @@ export default class UserItemModel extends BaseModel<UserItem> {
|
||||
|
||||
public async add(userId: Uuid, itemId: Uuid, options: SaveOptions = {}): Promise<void> {
|
||||
const item = await this.models().item().load(itemId, { fields: ['id', 'name'] });
|
||||
if (!item) {
|
||||
throw new ErrorNotFound(`No such item: ${itemId}`);
|
||||
}
|
||||
await this.addMulti(userId, [item], options);
|
||||
}
|
||||
|
||||
|
23
packages/server/src/models/UserItemModels.test.ts
Normal file
23
packages/server/src/models/UserItemModels.test.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { beforeAllDb, afterAllTests, beforeEachDb, models } from '../utils/testing/testUtils';
|
||||
|
||||
describe('UserItemModel', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
await beforeAllDb('UserItemModel');
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await afterAllTests();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await beforeEachDb();
|
||||
});
|
||||
|
||||
test('should throw error if item does not exist', async () => {
|
||||
const mockUserId = 'not-a-real-user-id';
|
||||
const mockId = 'not-a-real-item-id';
|
||||
expect(async () => models().userItem().add(mockUserId, mockId)).rejects.toThrow('No such item: not-a-real-item-id');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user