|
| 1 | +import { isAfter } from 'date-fns'; |
1 | 2 | import { eq } from 'drizzle-orm'; |
2 | 3 | import { StatusCodes } from 'http-status-codes'; |
3 | 4 |
|
@@ -325,6 +326,40 @@ describe('Item Like', () => { |
325 | 326 | expect(savedLikes[1].creatorId).toEqual(actor.id); |
326 | 327 | }); |
327 | 328 |
|
| 329 | + it('Allows to override like if already exist', async () => { |
| 330 | + const { |
| 331 | + actor, |
| 332 | + items: [item], |
| 333 | + } = await seedFromJson({ |
| 334 | + items: [ |
| 335 | + { |
| 336 | + likes: ['actor'], |
| 337 | + memberships: [{ account: 'actor', permission: PermissionLevel.Read }], |
| 338 | + }, |
| 339 | + ], |
| 340 | + }); |
| 341 | + assertIsDefined(actor); |
| 342 | + assertIsMember(actor); |
| 343 | + mockAuthenticate(actor); |
| 344 | + const [initialLike] = await getItemLikesByItem(item.id); |
| 345 | + |
| 346 | + const res = await app.inject({ |
| 347 | + method: HttpMethod.Post, |
| 348 | + url: `/items/${item.id}/like`, |
| 349 | + }); |
| 350 | + expect(res.statusCode).toBe(StatusCodes.OK); |
| 351 | + // the creatorId should be the same |
| 352 | + const result = await res.json(); |
| 353 | + expect(result.creatorId).toEqual(actor.id); |
| 354 | + |
| 355 | + // check received item like |
| 356 | + // since we don't have full item, deduce from saved value |
| 357 | + const savedLikes = await getItemLikesByItem(item.id); |
| 358 | + expect(savedLikes).toHaveLength(1); |
| 359 | + expect(savedLikes[0].creatorId).toEqual(actor.id); |
| 360 | + expect(isAfter(savedLikes[0].createdAt, initialLike.createdAt)).toBeTruthy(); |
| 361 | + }); |
| 362 | + |
328 | 363 | it('Cannot like item if does not have rights', async () => { |
329 | 364 | const { |
330 | 365 | actor, |
|
0 commit comments