diff --git a/src/modules/regexps/regexps.controller.ts b/src/modules/regexps/regexps.controller.ts index a418ef4..84db6c6 100644 --- a/src/modules/regexps/regexps.controller.ts +++ b/src/modules/regexps/regexps.controller.ts @@ -72,19 +72,9 @@ export class RegexpsAdminController { @ApiOperation({ title: "Edit RegExp" }) // endregion Swagger Docs public async edit(@Body() ctx: EditRegexpDot, @Param() param: RidDto) { - const data: EditRegexpRawDot = { }; - if (ctx.name) { data.name = ctx.name; } - if (ctx.value) { data.value = ctx.value; } - if (ctx.link) { data.link = ctx.link; } - if (ctx.hidden !== null && ctx.hidden !== undefined) { - data.hidden = ctx.hidden; - } - if (Object.keys(data).length === 0) { - throw new BadRequestException("No Params"); - } - const regexp = await this.regexpsSvr.editById(param.rid, data); + const regexp = await this.regexpsSvr.editById(param.rid, ctx); if (!regexp) { - throw new BadRequestException("NonExist RegExp"); + throw new BadRequestException("Non Exist RegExp"); } return new DefResDto(); } diff --git a/test/api/regexps.e2e.ts b/test/api/regexps.e2e.ts index 514b0d4..59e9751 100644 --- a/test/api/regexps.e2e.ts +++ b/test/api/regexps.e2e.ts @@ -177,7 +177,7 @@ describe("Regexp E2E Api", () => { status.should.be.eql(400); }); - step("Modify with Empty Param", async () => { + xstep("Modify with Empty Param", async () => { const raw = await RegexpsModel.addRegexp( newName(), "^empty.param" ); diff --git a/test/issues/gitlab/issue_2.e2e.ts b/test/issues/gitlab/issue_2.e2e.ts new file mode 100644 index 0000000..59c180f --- /dev/null +++ b/test/issues/gitlab/issue_2.e2e.ts @@ -0,0 +1,88 @@ +import * as supertest from "supertest"; +import categories = require("@db/categories"); +import auth = require("@db/auth"); +import * as db from "../../helpers/database"; +import * as server from "../../helpers/server"; +import { newName } from "../../helpers/utils"; + +/** + * Fix [Issue 2](http://git.pbr.link/BoxSystem/StoreBox/issues/2) + */ +describe("Fix Issues", () => { + + let request: supertest.SuperTest; + + before(() => { + return db.connect(); + }); + + const ids = { + users: [ ], + categories: [ ], + regexps: [ ] + }; + + after(() => { + return db.drop(ids); + }); + + before(async () => { + request = await server.init(); + }); + + describe("Gitlab 2 [Cant Modify Regexp link]", () => { + + before("login", async () => { + ids.users.push((await auth.login(request))[0]); + }); + + let cids = [ ]; + step("Add Category group", async () => { + cids = await categories.addCategories(); + ids.categories.push(...cids); + }); + + step("Add One Category with Regexp", async () => { + const docs = await db.addCategoryAndRegexp( + new RegExp(newName()) + ); + ids.categories.push(docs[0]._id); + ids.regexps.push(docs[1]._id); + }); + + step("Modify Regexp link", async () => { + const url = `/api/v1/regexps/${ids.regexps[0]}`; + const targetId = ids.categories[10].toString(); + + const { status } = await request.post(url) + .send({ + link: targetId + }).then(); + status.should.be.not.eql(400); + + const { body } = await request.get(url).then(); + body.link._id.should.be.eql(targetId); + }); + + step("Delete Category", () => { + const targetId = ids.categories[10].toString(); + const url = `/api/v1/categories/${targetId}`; + return request.delete(url).then(); + }); + + step("Modify Regexp link", async () => { + const url = `/api/v1/regexps/${ids.regexps[0]}`; + const targetId = ids.categories[8].toString(); + + const { status } = await request.post(url) + .send({ + link: targetId + }).then(); + status.should.be.not.eql(400); + + const { body } = await request.get(url).then(); + body.link._id.should.be.eql(targetId); + }); + + }); +});