Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/modules/regexps/regexps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion test/api/regexps.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
Expand Down
88 changes: 88 additions & 0 deletions test/issues/gitlab/issue_2.e2e.ts
Original file line number Diff line number Diff line change
@@ -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<supertest.Test>;

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);
});

});
});