Skip to content

Commit

Permalink
v2 observation_photos create accepts position attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jun 5, 2024
1 parent 8997cf5 commit bb9a1b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion openapi/paths/v2/observation_sounds/{uuid}.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = sendWrapper => {
}

PUT.apiDoc = {
tags: ["ObservationPhotos"],
tags: ["ObservationSounds"],
summary: "Update an observation sound",
security: [{
userJwtRequired: []
Expand Down
1 change: 1 addition & 0 deletions openapi/schema/request/observation_photos_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = Joi.object( )
.description( "UUID for the existing observation" ),
photo_id: Joi.number( ).integer( )
.description( "Sequential ID for the existing photo" ),
position: Joi.number( ).integer( ),
uuid: Joi.string( ).guid( { version: "uuidv4" } )
.description(
"New UUID for the photo, helps prevent duplication in poor network conditions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = Joi.object( ).keys( {
.description(
"New UUID for the photo, helps prevent duplication in poor network conditions"
),
"observation_photo[position]": Joi.number( ).integer( ),
file: Joi.binary( ).required( )
} ).unknown( true );
12 changes: 9 additions & 3 deletions test/integration/v2/observation_photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe( "ObservationPhotos", ( ) => {
id: 1234,
uuid: "b9576748-095f-43e4-ae25-0bb86ec74c47",
observation_id: "c1386ffd-1a87-40f7-b646-b9f716595567",
position: 0
position: 1
};

describe( "create", ( ) => {
Expand All @@ -26,14 +26,19 @@ describe( "ObservationPhotos", ( ) => {
request( this.app ).post( "/v2/observation_photos" )
.set( "Authorization", token )
.set( "Content-Type", "multipart/form-data" )
.field( "fields", "id,uuid" )
.field( "fields", "id,uuid,position" )
.field( "observation_photo[observation_id]", obsPhoto.observation_id )
.field( "observation_photo[position]", 1 )
.attach( "file", "test/fixtures/cuthona_abronia-tagged.jpg" )
.expect( 200 )
.expect( res => {
// NOTE: these properties are just what was stubbed with `const obsPhoto` above, so
// this just tests that the endpoint was hit without error and returned what we
// instructed it to return
const resObj = res.body.results[0];
expect( resObj.uuid ).to.eq( obsPhoto.uuid );
expect( resObj.id ).to.eq( obsPhoto.id );
expect( resObj.position ).to.eq( obsPhoto.position );
} )
.expect( "Content-Type", /json/ )
.expect( 200, done );
Expand All @@ -50,7 +55,8 @@ describe( "ObservationPhotos", ( ) => {
observation_photo: {
observation_id: obsPhoto.observation_id,
photo_id: 123,
uuid: obsPhoto.uuid
uuid: obsPhoto.uuid,
position: 2
}
} )
.expect( 200, done );
Expand Down

0 comments on commit bb9a1b2

Please sign in to comment.