Skip to content
Closed
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
22 changes: 11 additions & 11 deletions config/mappings/agmarknet/mandi-price.select.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ required:
and $match($ra.market.state, /^[A-Za-z]{2,4}$/)
)
message: "this capability needs Agmarknet's codes in market: a numeric district and a short alphabetic state, not their names"
- check: |
(
$ra := beckn.message.contract.commitments[0].resources[0].resourceAttributes;
/* market.marketCode, where the catalog advertises it. Absent or empty, Agmarknet
widens the query to the whole district. $string("") is not "" here, so compare raw. */
$exists($ra.market.marketCode) and $ra.market.marketCode != ""
)
message: "this capability needs a market code in market.marketCode, as the catalog lists it; without it the query widens to the whole district"
- check: |
(
$ra := beckn.message.contract.commitments[0].resources[0].resourceAttributes;
Expand Down Expand Up @@ -338,18 +346,10 @@ response: |
"commodityGroup": $r.Group,
"variety": $r.Variety,
"grade": $r.Grade,
/* Every member comes from the RECORD, so the answer describes what
the provider reported rather than what was asked for.

marketCode is absent, and that is not an omission. This upstream
TAKES a market code as a query parameter and reports none back --
there is no such field anywhere in its response. Restating the
requested code against a returned row would assert something
unverified, and district-wide there is no requested code at all
while the rows come from several markets, so one code would have
been wrong for most of them. The pack requires only marketName
and calls marketCode "when available"; here it is not. */
/* From the RECORD, except marketCode: the upstream reports none, so it is the
requested one (guarded), placed where catalog-ondemand.yaml puts it. */
"market": {
"marketCode": $ra.market.marketCode,
"marketName": $r.Market,
"district": $r.District,
"state": $r.State
Expand Down
25 changes: 22 additions & 3 deletions pkg/plugin/implementation/MandiPrice/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,11 @@ func TestShippedMappingStatesWhatItKnowsRatherThanEchoing(t *testing.T) {
}

market, _ := ra["market"].(map[string]any)
// The upstream reports no market code, so the answer must not claim one.
if code, present := market["marketCode"]; present {
t.Errorf("market.marketCode = %#v; this upstream reports no code, so asserting one is unfounded", code)
// The upstream reports no market code, but the select requires one and
// the query is scoped to it, so every row is that market's. The code
// sits where the catalog advertised it: market.marketCode.
if market["marketCode"] != "2056" {
t.Errorf("market.marketCode = %#v, want the requested \"2056\"", market["marketCode"])
}
// And what is there comes from the record.
if market["marketName"] != "Kasdol APMC" || market["state"] != "Chattisgarh" {
Expand Down Expand Up @@ -722,6 +724,23 @@ func TestShippedMappingRefusesPayloadsItCannotAnswer(t *testing.T) {
},
expect: "codes in market",
},
{
// Without a market code the upstream widens the query to the whole
// district, and the answer can no longer say which market it is for.
name: "no market code",
mutate: func(ra map[string]any) {
delete(ra["market"].(map[string]any), "marketCode")
},
expect: "market code",
},
{
// Present but empty names no market either.
name: "an empty market code",
mutate: func(ra map[string]any) {
ra["market"].(map[string]any)["marketCode"] = ""
},
expect: "market code",
},
{
// Everything downstream reads supportedCommodities[0], so this
// used to be queried for Paddy alone and answered confidently.
Expand Down
Loading