@@ -952,6 +952,231 @@ medusaIntegrationTestRunner({
952952 } ) ,
953953 ] )
954954 } )
955+
956+ it ( "returns a list of products filtered by variants[ean]" , async ( ) => {
957+ const productWithEan = await api . post (
958+ "/admin/products" ,
959+ getProductFixture ( {
960+ title : "Product with EAN" ,
961+ shipping_profile_id : shippingProfile . id ,
962+ variants : [
963+ {
964+ title : "Test variant" ,
965+ ean : "1234567890123" ,
966+ prices : [ { currency_code : "usd" , amount : 100 } ] ,
967+ options : {
968+ size : "large" ,
969+ color : "green" ,
970+ } ,
971+ } ,
972+ ] ,
973+ } ) ,
974+ adminHeaders
975+ )
976+
977+ await api . post (
978+ "/admin/products" ,
979+ getProductFixture ( {
980+ title : "Product with different EAN" ,
981+ shipping_profile_id : shippingProfile . id ,
982+ variants : [
983+ {
984+ title : "Test variant 2" ,
985+ ean : "9876543210987" ,
986+ prices : [ { currency_code : "usd" , amount : 150 } ] ,
987+ options : {
988+ size : "large" ,
989+ color : "green" ,
990+ } ,
991+ } ,
992+ ] ,
993+ } ) ,
994+ adminHeaders
995+ )
996+
997+ const response = await api
998+ . get ( "/admin/products?variants[ean]=1234567890123" , adminHeaders )
999+ . catch ( ( err ) => {
1000+ console . log ( err )
1001+ } )
1002+
1003+ expect ( response . status ) . toEqual ( 200 )
1004+ expect ( response . data . products ) . toHaveLength ( 1 )
1005+ expect ( response . data . products ) . toEqual (
1006+ expect . arrayContaining ( [
1007+ expect . objectContaining ( {
1008+ id : productWithEan . data . product . id ,
1009+ title : "Product with EAN" ,
1010+ variants : expect . arrayContaining ( [
1011+ expect . objectContaining ( {
1012+ ean : "1234567890123" ,
1013+ } ) ,
1014+ ] ) ,
1015+ } ) ,
1016+ ] )
1017+ )
1018+ } )
1019+
1020+ it ( "returns a list of products filtered by variants[upc]" , async ( ) => {
1021+ const productWithUpc = await api . post (
1022+ "/admin/products" ,
1023+ getProductFixture ( {
1024+ title : "Product with UPC" ,
1025+ shipping_profile_id : shippingProfile . id ,
1026+ variants : [
1027+ {
1028+ title : "Test variant" ,
1029+ upc : "123456789012" ,
1030+ prices : [ { currency_code : "usd" , amount : 200 } ] ,
1031+ options : {
1032+ size : "large" ,
1033+ color : "green" ,
1034+ } ,
1035+ } ,
1036+ ] ,
1037+ } ) ,
1038+ adminHeaders
1039+ )
1040+
1041+ await api . post (
1042+ "/admin/products" ,
1043+ getProductFixture ( {
1044+ title : "Product with different UPC" ,
1045+ shipping_profile_id : shippingProfile . id ,
1046+ variants : [
1047+ {
1048+ title : "Test variant 2" ,
1049+ upc : "098765432109" ,
1050+ prices : [ { currency_code : "usd" , amount : 250 } ] ,
1051+ options : {
1052+ size : "large" ,
1053+ color : "green" ,
1054+ } ,
1055+ } ,
1056+ ] ,
1057+ } ) ,
1058+ adminHeaders
1059+ )
1060+
1061+ const response = await api
1062+ . get ( "/admin/products?variants[upc]=123456789012" , adminHeaders )
1063+ . catch ( ( err ) => {
1064+ console . log ( err )
1065+ } )
1066+
1067+ expect ( response . status ) . toEqual ( 200 )
1068+ expect ( response . data . products ) . toHaveLength ( 1 )
1069+ expect ( response . data . products ) . toEqual (
1070+ expect . arrayContaining ( [
1071+ expect . objectContaining ( {
1072+ id : productWithUpc . data . product . id ,
1073+ title : "Product with UPC" ,
1074+ variants : expect . arrayContaining ( [
1075+ expect . objectContaining ( {
1076+ upc : "123456789012" ,
1077+ } ) ,
1078+ ] ) ,
1079+ } ) ,
1080+ ] )
1081+ )
1082+ } )
1083+
1084+ it ( "returns a list of products filtered by variants[barcode]" , async ( ) => {
1085+ const productWithBarcode = await api . post (
1086+ "/admin/products" ,
1087+ getProductFixture ( {
1088+ title : "Product with Barcode" ,
1089+ shipping_profile_id : shippingProfile . id ,
1090+ variants : [
1091+ {
1092+ title : "Test variant" ,
1093+ barcode : "1234567890" ,
1094+ prices : [ { currency_code : "usd" , amount : 300 } ] ,
1095+ options : {
1096+ size : "large" ,
1097+ color : "green" ,
1098+ } ,
1099+ } ,
1100+ ] ,
1101+ } ) ,
1102+ adminHeaders
1103+ )
1104+
1105+ await api . post (
1106+ "/admin/products" ,
1107+ getProductFixture ( {
1108+ title : "Product with different Barcode" ,
1109+ shipping_profile_id : shippingProfile . id ,
1110+ variants : [
1111+ {
1112+ title : "Test variant 2" ,
1113+ barcode : "0987654321" ,
1114+ prices : [ { currency_code : "usd" , amount : 350 } ] ,
1115+ options : {
1116+ size : "large" ,
1117+ color : "green" ,
1118+ } ,
1119+ } ,
1120+ ] ,
1121+ } ) ,
1122+ adminHeaders
1123+ )
1124+
1125+ const response = await api
1126+ . get ( "/admin/products?variants[barcode]=1234567890" , adminHeaders )
1127+ . catch ( ( err ) => {
1128+ console . log ( err )
1129+ } )
1130+
1131+ expect ( response . status ) . toEqual ( 200 )
1132+ expect ( response . data . products ) . toHaveLength ( 1 )
1133+ expect ( response . data . products ) . toEqual (
1134+ expect . arrayContaining ( [
1135+ expect . objectContaining ( {
1136+ id : productWithBarcode . data . product . id ,
1137+ title : "Product with Barcode" ,
1138+ variants : expect . arrayContaining ( [
1139+ expect . objectContaining ( {
1140+ barcode : "1234567890" ,
1141+ } ) ,
1142+ ] ) ,
1143+ } ) ,
1144+ ] )
1145+ )
1146+ } )
1147+
1148+ it ( "returns empty list when filtering by non-existent variants[ean]" , async ( ) => {
1149+ const response = await api
1150+ . get ( "/admin/products?variants[ean]=5555555555555" , adminHeaders )
1151+ . catch ( ( err ) => {
1152+ console . log ( err )
1153+ } )
1154+
1155+ expect ( response . status ) . toEqual ( 200 )
1156+ expect ( response . data . products ) . toHaveLength ( 0 )
1157+ } )
1158+
1159+ it ( "returns empty list when filtering by non-existent variants[upc]" , async ( ) => {
1160+ const response = await api
1161+ . get ( "/admin/products?variants[upc]=555555555555" , adminHeaders )
1162+ . catch ( ( err ) => {
1163+ console . log ( err )
1164+ } )
1165+
1166+ expect ( response . status ) . toEqual ( 200 )
1167+ expect ( response . data . products ) . toHaveLength ( 0 )
1168+ } )
1169+
1170+ it ( "returns empty list when filtering by non-existent variants[barcode]" , async ( ) => {
1171+ const response = await api
1172+ . get ( "/admin/products?variants[barcode]=5555555555" , adminHeaders )
1173+ . catch ( ( err ) => {
1174+ console . log ( err )
1175+ } )
1176+
1177+ expect ( response . status ) . toEqual ( 200 )
1178+ expect ( response . data . products ) . toHaveLength ( 0 )
1179+ } )
9551180 } )
9561181
9571182 describe ( "GET /admin/products/:id" , ( ) => {
0 commit comments