v1.0.0 #28
|
@ -4,12 +4,10 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.11",
|
"@types/jest": "^29.5.11",
|
||||||
"@types/mongodb-memory-server": "^2.3.0",
|
|
||||||
"@types/supertest": "^6.0.1",
|
"@types/supertest": "^6.0.1",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/express-list-endpoints": "^6.0.3",
|
"@types/express-list-endpoints": "^6.0.3",
|
||||||
"@types/jsonwebtoken": "^9.0.5",
|
"@types/jsonwebtoken": "^9.0.5",
|
||||||
"@types/mongoose": "^5.11.97",
|
|
||||||
"bun-types": "latest",
|
"bun-types": "latest",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"mongodb-memory-server": "^9.1.3",
|
"mongodb-memory-server": "^9.1.3",
|
||||||
|
@ -30,10 +28,5 @@
|
||||||
"express-list-endpoints": "^6.0.0",
|
"express-list-endpoints": "^6.0.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"mongoose": "^8.0.3"
|
"mongoose": "^8.0.3"
|
||||||
},
|
|
||||||
"config": {
|
|
||||||
"mongodbMemoryServer": {
|
|
||||||
"debug": "1"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,6 @@ export const startApp = async () => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default app;
|
export default app;
|
|
@ -23,9 +23,7 @@ class ImageController {
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error instanceof mongo.MongoServerError && error.code === 11000) {
|
if (error instanceof mongo.MongoServerError && error.code === 11000) {
|
||||||
// Should return 409 Conflict for existing urls
|
// Should return 409 Conflict for existing urls
|
||||||
res
|
res.status(409).json({
|
||||||
.status(409)
|
|
||||||
.json({
|
|
||||||
error: `the image with URL ${error.keyValue.url} already exists`,
|
error: `the image with URL ${error.keyValue.url} already exists`,
|
||||||
});
|
});
|
||||||
} else if (error instanceof mongoose.Error.ValidationError) {
|
} else if (error instanceof mongoose.Error.ValidationError) {
|
||||||
|
|
|
@ -3,10 +3,6 @@ import { startApp } from "./app";
|
||||||
|
|
||||||
await startApp();
|
await startApp();
|
||||||
|
|
||||||
|
try {
|
||||||
try{
|
|
||||||
await populateDatabase();
|
await populateDatabase();
|
||||||
}
|
} catch {}
|
||||||
catch {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ export interface Auth extends Document {
|
||||||
secret: String;
|
secret: String;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthSchema = new mongoose.Schema({
|
const AuthSchema = new mongoose.Schema(
|
||||||
|
{
|
||||||
app: {
|
app: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -15,6 +16,8 @@ const AuthSchema = new mongoose.Schema({
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
}, { collection: "authorizations" });
|
},
|
||||||
|
{ collection: "authorizations" }
|
||||||
|
);
|
||||||
|
|
||||||
export default mongoose.model("authorizations", AuthSchema);
|
export default mongoose.model("authorizations", AuthSchema);
|
||||||
|
|
|
@ -6,12 +6,13 @@ export interface Image extends Document {
|
||||||
tags?: String[];
|
tags?: String[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImageSchema = new mongoose.Schema({
|
const ImageSchema = new mongoose.Schema(
|
||||||
|
{
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
index: true,
|
index: true,
|
||||||
unique: true
|
unique: true,
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -24,6 +25,8 @@ const ImageSchema = new mongoose.Schema({
|
||||||
tags: {
|
tags: {
|
||||||
type: [String],
|
type: [String],
|
||||||
},
|
},
|
||||||
}, { collection: "images" });
|
},
|
||||||
|
{ collection: "images" }
|
||||||
|
);
|
||||||
|
|
||||||
export default mongoose.model<Image>("images", ImageSchema);
|
export default mongoose.model<Image>("images", ImageSchema);
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
import { afterAll, afterEach, beforeAll, describe, expect, it, mock } from "bun:test";
|
import {
|
||||||
|
afterAll,
|
||||||
|
afterEach,
|
||||||
|
beforeAll,
|
||||||
|
describe,
|
||||||
|
expect,
|
||||||
|
it,
|
||||||
|
mock,
|
||||||
|
} from "bun:test";
|
||||||
import request, { Response } from "supertest";
|
import request, { Response } from "supertest";
|
||||||
import app, { startApp } from "../src/app";
|
import app, { startApp } from "../src/app";
|
||||||
import imageService from "../src/services/ImageService";
|
import imageService from "../src/services/ImageService";
|
||||||
|
@ -10,8 +18,7 @@ const imageServiceOriginal = imageService;
|
||||||
let token: string;
|
let token: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
if (!process.env.DEDICATED_MONGODB_SERVER)
|
//if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.start();
|
||||||
await memoryServer.start();
|
|
||||||
await startApp();
|
await startApp();
|
||||||
await populateDatabase();
|
await populateDatabase();
|
||||||
|
|
||||||
|
@ -21,11 +28,10 @@ beforeAll(async () => {
|
||||||
token = tok.body.token;
|
token = tok.body.token;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
/* afterAll(async () => {
|
||||||
if (!process.env.DEDICATED_MONGODB_SERVER)
|
if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.stop();
|
||||||
await memoryServer.stop();
|
});
|
||||||
})
|
*/
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mock.restore();
|
mock.restore();
|
||||||
mock.module("../src/services/ImageService", () => ({
|
mock.module("../src/services/ImageService", () => ({
|
||||||
|
@ -53,7 +59,7 @@ describe("/login works as instended", async () => {
|
||||||
const res = await request(app).post("/login").send({});
|
const res = await request(app).post("/login").send({});
|
||||||
expect(res.status).toBe(403);
|
expect(res.status).toBe(403);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GET / shows all of the endpoints", async () => {
|
describe("GET / shows all of the endpoints", async () => {
|
||||||
const res = await request(app).get("/");
|
const res = await request(app).get("/");
|
||||||
|
|
Loading…
Reference in New Issue