Skip to content

Commit 3e972b8

Browse files
committed
refactor: set no_html to true when creating identifications
1 parent fecf067 commit 3e972b8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/controllers/v1/identifications_controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const InaturalistAPI = require( "../../inaturalist_api" );
1212

1313
const IdentificationsController = class IdentificationsController {
1414
static async create( req ) {
15+
req.body ||= { };
16+
req.body.no_html = true;
1517
const response = await InaturalistAPI.iNatJSWrap( identifications.create, req );
1618
const arr = [{ identification_id: response.id }];
1719
const localeOpts = util.localeOpts( req );

test/integration/v1/identifications.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const { expect } = require( "chai" );
22
const request = require( "supertest" );
33
const fs = require( "fs" );
44
const _ = require( "lodash" );
5+
const jwt = require( "jsonwebtoken" );
6+
const nock = require( "nock" );
7+
const config = require( "../../../config" );
58

69
const fixtures = JSON.parse( fs.readFileSync( "schema/fixtures.js" ) );
710

@@ -64,6 +67,28 @@ describe( "Identifications", ( ) => {
6467
} );
6568
} );
6669

70+
describe( "create", ( ) => {
71+
it( "sets `no_html` to true for all passthrough requests", function ( done ) {
72+
const token = jwt.sign( { user_id: 1 },
73+
config.jwtSecret || "secret",
74+
{ algorithm: "HS512" } );
75+
nock( "http://localhost:3000" )
76+
.post( "/identifications", body => {
77+
expect( body.no_html ).to.eq( true );
78+
return body;
79+
} )
80+
.reply( 200, [] );
81+
request( this.app ).post( "/v1/identifications", {
82+
identification: {
83+
observation_id: 1
84+
}
85+
} )
86+
.set( "Authorization", token )
87+
.expect( "Content-Type", /json/ )
88+
.expect( 200, done );
89+
} );
90+
} );
91+
6792
describe( "details", ( ) => {
6893
it( "never returns email or IP for user in identification", function ( done ) {
6994
request( this.app ).get( "/v1/identifications/2023092501" )

0 commit comments

Comments
 (0)