Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 60c9a32

Browse files
authored
[RND-637] - Unable to POST a new School (#295)
* Fixes bug. * Adds e2e test.
1 parent e177823 commit 60c9a32

File tree

3 files changed

+181
-2
lines changed

3 files changed

+181
-2
lines changed

Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/ReferenceValidation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function findMissingReferences(
5151
// eslint-disable-next-line no-underscore-dangle
5252
const meadowlarkIdsOfRefsInDb: MeadowlarkId[] = refsInDb.map((outRef) =>
5353
// eslint-disable-next-line no-underscore-dangle
54-
outRef.aliasMeadowlarkIds.length > 0 ? outRef.aliasMeadowlarkIds[0] : outRef._id,
54+
outRef.aliasMeadowlarkIds && outRef.aliasMeadowlarkIds.length > 0 ? outRef.aliasMeadowlarkIds[0] : outRef._id,
5555
);
5656
const outRefMeadowlarkIdsNotInDb: MeadowlarkId[] = R.difference(documentOutboundRefs, meadowlarkIdsOfRefsInDb);
5757

Meadowlark-js/tests/e2e/scenarios/ResourcesReferenceValidation.test.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { baseURLRequest, rootURLRequest } from '../helpers/Shared';
1111
describe('When creating a resource that has a reference to another resource', () => {
1212
describe('given a token with strict validation', () => {
1313
describe('given reference does not exist', () => {
14-
it('should fail with code 400 and a message', async () => {
14+
it('should fail with code 409 and a message', async () => {
1515
await baseURLRequest()
1616
.post('/v3.3b/ed-fi/locations')
1717
.auth(await getAccessToken('vendor'), { type: 'bearer' })
@@ -44,6 +44,68 @@ describe('When creating a resource that has a reference to another resource', ()
4444
});
4545
});
4646

47+
describe('given descriptor references exists and two descriptor references do not exist', () => {
48+
it('should fail with code 409 and a message', async () => {
49+
await baseURLRequest()
50+
.post('/v3.3b/ed-fi/EducationOrganizationCategoryDescriptors')
51+
.auth(await getAccessToken('vendor'), { type: 'bearer' })
52+
.send({
53+
codeValue: 'Other',
54+
shortDescription: 'Other',
55+
description: 'Other',
56+
namespace: 'uri://ed-fi.org/EducationOrganizationCategoryDescriptor',
57+
})
58+
.expect(201);
59+
60+
await baseURLRequest()
61+
.post('/v3.3b/ed-fi/schools')
62+
.auth(await getAccessToken('vendor'), { type: 'bearer' })
63+
.send({
64+
schoolId: 124,
65+
nameOfInstitution: 'A School',
66+
educationOrganizationCategories: [
67+
{
68+
educationOrganizationCategoryDescriptor: 'uri://ed-fi.org/EducationOrganizationCategoryDescriptor#Other',
69+
},
70+
],
71+
schoolCategories: [
72+
{
73+
schoolCategoryDescriptor: 'uri://ed-fi.org/SchoolCategoryDescriptor#All Levels',
74+
},
75+
],
76+
gradeLevels: [
77+
{
78+
gradeLevelDescriptor: 'uri://ed-fi.org/GradeLevelDescriptor#First Grade',
79+
},
80+
],
81+
})
82+
.expect(409)
83+
.then((response) => {
84+
expect(response.body).toMatchInlineSnapshot(`
85+
{
86+
"error": {
87+
"failures": [
88+
{
89+
"identity": {
90+
"descriptor": "uri://ed-fi.org/GradeLevelDescriptor#First Grade",
91+
},
92+
"resourceName": "GradeLevel",
93+
},
94+
{
95+
"identity": {
96+
"descriptor": "uri://ed-fi.org/SchoolCategoryDescriptor#All Levels",
97+
},
98+
"resourceName": "SchoolCategory",
99+
},
100+
],
101+
"message": "Reference validation failed",
102+
},
103+
}
104+
`);
105+
});
106+
});
107+
});
108+
47109
describe('given the reference does exist', () => {
48110
let schoolId: number;
49111
let schoolLocation: string;

Meadowlark-js/tests/http/RND-637.http

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
@admin_client_id=meadowlark_admin_key_1
3+
@admin_client_secret=meadowlark_admin_secret_1
4+
5+
### Authenticate admin
6+
# @name admin1
7+
POST http://localhost:3000/local/oauth/token
8+
content-type: application/json
9+
10+
{
11+
"grant_type": "client_credentials",
12+
"client_id": "{{admin_client_id}}",
13+
"client_secret": "{{admin_client_secret}}"
14+
}
15+
16+
###
17+
@admin_token={{admin1.response.body.$.access_token}}
18+
@auth_header_admin_1=Authorization: bearer {{admin1.response.body.$.access_token}}
19+
20+
21+
### Create client1
22+
# @name created_client1
23+
POST http://localhost:3000/local/oauth/clients
24+
content-type: application/json
25+
{{auth_header_admin_1}}
26+
27+
{
28+
"clientName": "Hometown SIS",
29+
"roles": [
30+
"vendor"
31+
]
32+
}
33+
34+
###
35+
@client1_client_id={{created_client1.response.body.$.client_id}}
36+
@client1_client_secret={{created_client1.response.body.$.client_secret}}
37+
38+
### Authenticate client1
39+
# @name client1
40+
POST http://localhost:3000/local/oauth/token
41+
content-type: application/json
42+
43+
{
44+
"grant_type": "client_credentials",
45+
"client_id": "{{client1_client_id}}",
46+
"client_secret": "{{client1_client_secret}}"
47+
}
48+
49+
###
50+
@authToken1 = {{client1.response.body.$.access_token}}
51+
52+
53+
###
54+
POST http://localhost:3000/local/v3.3b/ed-fi/EducationOrganizationCategoryDescriptors
55+
content-type: application/json
56+
authorization: bearer {{authToken1}}
57+
58+
{
59+
"codeValue": "Other",
60+
"shortDescription": "Other",
61+
"description": "Other",
62+
"namespace": "uri://ed-fi.org/EducationOrganizationCategoryDescriptor"
63+
}
64+
65+
### This returns 409 error, since uri://ed-fi.org/SchoolCategoryDescriptor#All Levels
66+
# and uri://ed-fi.org/GradeLevelDescriptor#First Grade don't exist.
67+
POST http://localhost:3000/local/v3.3b/ed-fi/schools
68+
content-type: application/json
69+
authorization: bearer {{authToken1}}
70+
71+
{
72+
"schoolId": 124,
73+
"nameOfInstitution": "A School",
74+
"educationOrganizationCategories" : [
75+
{
76+
"educationOrganizationCategoryDescriptor": "uri://ed-fi.org/EducationOrganizationCategoryDescriptor#Other"
77+
}
78+
],
79+
"schoolCategories": [
80+
{
81+
"schoolCategoryDescriptor": "uri://ed-fi.org/SchoolCategoryDescriptor#All Levels"
82+
}
83+
],
84+
"gradeLevels": [
85+
{
86+
"gradeLevelDescriptor": "uri://ed-fi.org/GradeLevelDescriptor#First Grade"
87+
}
88+
]
89+
}
90+
91+
### These are the two descriptor needed in order to be able to successfully make the previous request.
92+
POST http://localhost:3000/local/v3.3b/ed-fi/SchoolCategoryDescriptors
93+
content-type: application/json
94+
authorization: bearer {{authToken1}}
95+
96+
{
97+
"codeValue": "All Levels",
98+
"shortDescription": "All Levels",
99+
"description": "All Levels",
100+
"namespace": "uri://ed-fi.org/SchoolCategoryDescriptor"
101+
}
102+
103+
###
104+
POST http://localhost:3000/local/v3.3b/ed-fi/GradeLevelDescriptors
105+
content-type: application/json
106+
authorization: bearer {{authToken1}}
107+
108+
{
109+
"codeValue": "First Grade",
110+
"shortDescription": "First Grade",
111+
"description": "First Grade",
112+
"namespace": "uri://ed-fi.org/GradeLevelDescriptor"
113+
}
114+
115+
#####
116+
GET http://localhost:3000/local/v3.3b/ed-fi/schools?nameOfInstitution=A School
117+
authorization: bearer {{authToken1}}

0 commit comments

Comments
 (0)