Skip to content

Commit 823f28d

Browse files
committed
Add multi condition operator in testcase
1 parent 1358344 commit 823f28d

File tree

1 file changed

+98
-42
lines changed

1 file changed

+98
-42
lines changed

tests/compound-bool.test.ts

Lines changed: 98 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -601,48 +601,6 @@ test('$exists Not Field Conditional Operator', async () => {
601601
});
602602
});
603603

604-
test('Data Type Error (Array)', async () => {
605-
const query = () => {
606-
const releaseYears = [2021, 2025];
607-
608-
const command = {
609-
release_year: {
610-
type: DataTypeEnum.TEXT,
611-
conditions: {
612-
$in: releaseYears
613-
}
614-
}
615-
}
616-
617-
const builder = new ElasticSearchDynamicQuery(command);
618-
return builder.compoundQuery().build()
619-
};
620-
expect(query).toThrow("field:release_year data type should by array!");
621-
});
622-
623-
test('Empty Condition Error', async () => {
624-
const query = () => {
625-
const releaseYear = 2020;
626-
627-
const command = {
628-
title: {
629-
type: DataTypeEnum.TEXT,
630-
conditions: {}
631-
},
632-
release_year: {
633-
type: DataTypeEnum.NUMBER,
634-
conditions: {
635-
$eq: releaseYear
636-
}
637-
}
638-
}
639-
const builder = new ElasticSearchDynamicQuery(command);
640-
return builder.compoundQuery().build()
641-
};
642-
643-
expect(query).toThrow("title has no valid conditions!")
644-
});
645-
646604
test('$or Conditional Operator', async () => {
647605
const title = faker.lorem.word(2);
648606
const releaseYear = 2020;
@@ -742,3 +700,101 @@ test('$or (Partial) Conditional Operator', async () => {
742700
}
743701
});
744702
});
703+
704+
test('Data Type Error (Array)', async () => {
705+
const query = () => {
706+
const releaseYears = [2021, 2025];
707+
708+
const command = {
709+
release_year: {
710+
type: DataTypeEnum.TEXT,
711+
conditions: {
712+
$in: releaseYears
713+
}
714+
}
715+
}
716+
717+
const builder = new ElasticSearchDynamicQuery(command);
718+
return builder.compoundQuery().build()
719+
};
720+
expect(query).toThrow("field:release_year data type should by array!");
721+
});
722+
723+
test('Empty Condition Error', async () => {
724+
const query = () => {
725+
const releaseYear = 2020;
726+
727+
const command = {
728+
title: {
729+
type: DataTypeEnum.TEXT,
730+
conditions: {}
731+
},
732+
release_year: {
733+
type: DataTypeEnum.NUMBER,
734+
conditions: {
735+
$eq: releaseYear
736+
}
737+
}
738+
}
739+
const builder = new ElasticSearchDynamicQuery(command);
740+
return builder.compoundQuery().build()
741+
};
742+
743+
expect(query).toThrow("title has no valid conditions!")
744+
});
745+
746+
test('Multi Conditional Operator (1)', async () => {
747+
const title = faker.lorem.word(2);
748+
const anotherTitle = faker.lorem.word(3);
749+
750+
const releaseYear = 2022;
751+
const anotherReleaseYear = 2023;
752+
753+
const command = {
754+
title: {
755+
type: DataTypeEnum.TEXT,
756+
conditions: {
757+
$eq: title,
758+
$neq: anotherTitle
759+
}
760+
},
761+
release_year: {
762+
type: DataTypeEnum.NUMBER,
763+
conditions: {
764+
$eq: releaseYear,
765+
$neq: anotherReleaseYear
766+
}
767+
}
768+
}
769+
770+
const builder = new ElasticSearchDynamicQuery(command);
771+
const query = builder.compoundQuery().build();
772+
expect(query).toStrictEqual({
773+
bool: {
774+
must: [
775+
{
776+
match: {
777+
title: title
778+
}
779+
},
780+
{
781+
term: {
782+
release_year: releaseYear
783+
}
784+
}
785+
],
786+
must_not: [
787+
{
788+
match: {
789+
title: anotherTitle
790+
}
791+
},
792+
{
793+
term: {
794+
release_year: anotherReleaseYear
795+
}
796+
}
797+
]
798+
}
799+
});
800+
});

0 commit comments

Comments
 (0)