Skip to content

It should avoid conflicts in expose rules #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
43 changes: 42 additions & 1 deletion test/functional/basic-functionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,47 @@ describe("basic functionality", () => {

});

it("should avoid conflicts in expose rules", function () {

defaultMetadataStorage.clear();

@Exclude()
class User {

@Expose({ toClassOnly: true, groups: ["create", "update"] })
@Expose({ toPlainOnly: true })
public email?: string;

@Expose({ toClassOnly: true, groups: ["create", "update"] })
@Expose({ toPlainOnly: true })
public firstName?: string;

@Expose({ toClassOnly: true, groups: ["create"] })
@Expose({ toPlainOnly: true })
public password?: string;

}

const user = plainToClass(User, {
email: "email@example.com",
firstName: "John",
password: "12345"
}, { groups: ["update"] });

user.should.deep.equal({
email: "email@example.com",
firstName: "John"
});

const plain = classToPlain(user);

plain.should.deep.equal({
email: "email@example.com",
firstName: "John"
});

});

it("should transform objects with null prototype", () => {
class TestClass {
prop: string;
Expand All @@ -1694,4 +1735,4 @@ describe("basic functionality", () => {
transformedClass.should.be.instanceOf(TestClass);
});

});
});