Skip to content

Commit

Permalink
[RND-637] - Unable to POST a new School (#295)
Browse files Browse the repository at this point in the history
* Fixes bug.

* Adds e2e test.
  • Loading branch information
DavidJGapCR authored Sep 5, 2023
1 parent e177823 commit 60c9a32
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function findMissingReferences(
// eslint-disable-next-line no-underscore-dangle
const meadowlarkIdsOfRefsInDb: MeadowlarkId[] = refsInDb.map((outRef) =>
// eslint-disable-next-line no-underscore-dangle
outRef.aliasMeadowlarkIds.length > 0 ? outRef.aliasMeadowlarkIds[0] : outRef._id,
outRef.aliasMeadowlarkIds && outRef.aliasMeadowlarkIds.length > 0 ? outRef.aliasMeadowlarkIds[0] : outRef._id,
);
const outRefMeadowlarkIdsNotInDb: MeadowlarkId[] = R.difference(documentOutboundRefs, meadowlarkIdsOfRefsInDb);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { baseURLRequest, rootURLRequest } from '../helpers/Shared';
describe('When creating a resource that has a reference to another resource', () => {
describe('given a token with strict validation', () => {
describe('given reference does not exist', () => {
it('should fail with code 400 and a message', async () => {
it('should fail with code 409 and a message', async () => {
await baseURLRequest()
.post('/v3.3b/ed-fi/locations')
.auth(await getAccessToken('vendor'), { type: 'bearer' })
Expand Down Expand Up @@ -44,6 +44,68 @@ describe('When creating a resource that has a reference to another resource', ()
});
});

describe('given descriptor references exists and two descriptor references do not exist', () => {
it('should fail with code 409 and a message', async () => {
await baseURLRequest()
.post('/v3.3b/ed-fi/EducationOrganizationCategoryDescriptors')
.auth(await getAccessToken('vendor'), { type: 'bearer' })
.send({
codeValue: 'Other',
shortDescription: 'Other',
description: 'Other',
namespace: 'uri://ed-fi.org/EducationOrganizationCategoryDescriptor',
})
.expect(201);

await baseURLRequest()
.post('/v3.3b/ed-fi/schools')
.auth(await getAccessToken('vendor'), { type: 'bearer' })
.send({
schoolId: 124,
nameOfInstitution: 'A School',
educationOrganizationCategories: [
{
educationOrganizationCategoryDescriptor: 'uri://ed-fi.org/EducationOrganizationCategoryDescriptor#Other',
},
],
schoolCategories: [
{
schoolCategoryDescriptor: 'uri://ed-fi.org/SchoolCategoryDescriptor#All Levels',
},
],
gradeLevels: [
{
gradeLevelDescriptor: 'uri://ed-fi.org/GradeLevelDescriptor#First Grade',
},
],
})
.expect(409)
.then((response) => {
expect(response.body).toMatchInlineSnapshot(`
{
"error": {
"failures": [
{
"identity": {
"descriptor": "uri://ed-fi.org/GradeLevelDescriptor#First Grade",
},
"resourceName": "GradeLevel",
},
{
"identity": {
"descriptor": "uri://ed-fi.org/SchoolCategoryDescriptor#All Levels",
},
"resourceName": "SchoolCategory",
},
],
"message": "Reference validation failed",
},
}
`);
});
});
});

describe('given the reference does exist', () => {
let schoolId: number;
let schoolLocation: string;
Expand Down
117 changes: 117 additions & 0 deletions Meadowlark-js/tests/http/RND-637.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

@admin_client_id=meadowlark_admin_key_1
@admin_client_secret=meadowlark_admin_secret_1

### Authenticate admin
# @name admin1
POST http://localhost:3000/local/oauth/token
content-type: application/json

{
"grant_type": "client_credentials",
"client_id": "{{admin_client_id}}",
"client_secret": "{{admin_client_secret}}"
}

###
@admin_token={{admin1.response.body.$.access_token}}
@auth_header_admin_1=Authorization: bearer {{admin1.response.body.$.access_token}}


### Create client1
# @name created_client1
POST http://localhost:3000/local/oauth/clients
content-type: application/json
{{auth_header_admin_1}}

{
"clientName": "Hometown SIS",
"roles": [
"vendor"
]
}

###
@client1_client_id={{created_client1.response.body.$.client_id}}
@client1_client_secret={{created_client1.response.body.$.client_secret}}

### Authenticate client1
# @name client1
POST http://localhost:3000/local/oauth/token
content-type: application/json

{
"grant_type": "client_credentials",
"client_id": "{{client1_client_id}}",
"client_secret": "{{client1_client_secret}}"
}

###
@authToken1 = {{client1.response.body.$.access_token}}


###
POST http://localhost:3000/local/v3.3b/ed-fi/EducationOrganizationCategoryDescriptors
content-type: application/json
authorization: bearer {{authToken1}}

{
"codeValue": "Other",
"shortDescription": "Other",
"description": "Other",
"namespace": "uri://ed-fi.org/EducationOrganizationCategoryDescriptor"
}

### This returns 409 error, since uri://ed-fi.org/SchoolCategoryDescriptor#All Levels
# and uri://ed-fi.org/GradeLevelDescriptor#First Grade don't exist.
POST http://localhost:3000/local/v3.3b/ed-fi/schools
content-type: application/json
authorization: bearer {{authToken1}}

{
"schoolId": 124,
"nameOfInstitution": "A School",
"educationOrganizationCategories" : [
{
"educationOrganizationCategoryDescriptor": "uri://ed-fi.org/EducationOrganizationCategoryDescriptor#Other"
}
],
"schoolCategories": [
{
"schoolCategoryDescriptor": "uri://ed-fi.org/SchoolCategoryDescriptor#All Levels"
}
],
"gradeLevels": [
{
"gradeLevelDescriptor": "uri://ed-fi.org/GradeLevelDescriptor#First Grade"
}
]
}

### These are the two descriptor needed in order to be able to successfully make the previous request.
POST http://localhost:3000/local/v3.3b/ed-fi/SchoolCategoryDescriptors
content-type: application/json
authorization: bearer {{authToken1}}

{
"codeValue": "All Levels",
"shortDescription": "All Levels",
"description": "All Levels",
"namespace": "uri://ed-fi.org/SchoolCategoryDescriptor"
}

###
POST http://localhost:3000/local/v3.3b/ed-fi/GradeLevelDescriptors
content-type: application/json
authorization: bearer {{authToken1}}

{
"codeValue": "First Grade",
"shortDescription": "First Grade",
"description": "First Grade",
"namespace": "uri://ed-fi.org/GradeLevelDescriptor"
}

#####
GET http://localhost:3000/local/v3.3b/ed-fi/schools?nameOfInstitution=A School
authorization: bearer {{authToken1}}

0 comments on commit 60c9a32

Please sign in to comment.