mirror of
https://github.com/usatiuk/photos.git
synced 2025-10-28 23:37:48 +01:00
do not allow uploading same photo twice
This commit is contained in:
@@ -43,6 +43,7 @@ export interface IPhotoReqJSON extends IPhotoJSON {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@Index(["hash", "size", "user"], { unique: true })
|
||||||
export class Photo extends BaseEntity {
|
export class Photo extends BaseEntity {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
public id: number;
|
public id: number;
|
||||||
|
|||||||
@@ -212,6 +212,36 @@ describe("photos", function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not create a photo twice", async function () {
|
||||||
|
const response = await request(callback)
|
||||||
|
.post("/photos/new")
|
||||||
|
.set({
|
||||||
|
Authorization: `Bearer ${seed.user1.toJWT()}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
})
|
||||||
|
.send({
|
||||||
|
hash: dogHash,
|
||||||
|
size: dogSize,
|
||||||
|
format: dogFormat,
|
||||||
|
} as IPhotosNewPostBody)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(response.body.error).to.be.false;
|
||||||
|
|
||||||
|
const response2 = await request(callback)
|
||||||
|
.post("/photos/new")
|
||||||
|
.set({
|
||||||
|
Authorization: `Bearer ${seed.user1.toJWT()}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
})
|
||||||
|
.send({
|
||||||
|
hash: dogHash,
|
||||||
|
size: dogSize,
|
||||||
|
format: dogFormat,
|
||||||
|
} as IPhotosNewPostBody)
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
|
|
||||||
it("should not upload a photo twice", async function () {
|
it("should not upload a photo twice", async function () {
|
||||||
const response = await request(callback)
|
const response = await request(callback)
|
||||||
.post("/photos/new")
|
.post("/photos/new")
|
||||||
@@ -457,7 +487,10 @@ describe("photos", function () {
|
|||||||
|
|
||||||
const photos = response.body.data as IPhotoReqJSON[];
|
const photos = response.body.data as IPhotoReqJSON[];
|
||||||
|
|
||||||
const userPhotos = [seed.dogPhoto.toReqJSON(), seed.catPhoto.toReqJSON()];
|
const userPhotos = [
|
||||||
|
seed.dogPhoto.toReqJSON(),
|
||||||
|
seed.catPhoto.toReqJSON(),
|
||||||
|
];
|
||||||
|
|
||||||
expect(photos).to.deep.equal(userPhotos);
|
expect(photos).to.deep.equal(userPhotos);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user