-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-velocity-template): expression not equals works unproperly (
#5571) When used with amplify-appsync-simulator the not equals (!=) expression doesn't work properly. Two strings are considered inequal when should be considered equals. fix #5570 Co-authored-by: Fernando Chucre <fernando@oraoncology.com>
- Loading branch information
Showing
3 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/amplify-appsync-simulator/src/__tests__/velocity/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { AmplifyAppSyncSimulator } from '../..'; | ||
import { AmplifyAppSyncSimulatorAuthenticationType } from '../../type-definition'; | ||
import { VelocityTemplate } from '../../velocity'; | ||
import { mockInfo } from './util/general-utils.test'; | ||
|
||
describe('VelocityTemplate', () => { | ||
let content; | ||
let simulator; | ||
beforeAll(() => { | ||
content = `"$ctx.error.message, $ctx.error.type"`; | ||
simulator = new AmplifyAppSyncSimulator(); | ||
}); | ||
|
||
describe('#render', () => { | ||
it('should handle string comparison', () => { | ||
const template = new VelocityTemplate( | ||
{ | ||
path: 'INLINE_TEMPLATE', | ||
content: ` | ||
#if( $ctx.stash.get("current_user_id")!=$ctx.prev.result.current_user_id) | ||
"not the same value" | ||
#else | ||
"the same value" | ||
#end`, | ||
}, | ||
simulator, | ||
); | ||
const info = mockInfo; | ||
const result = template.render( | ||
{ | ||
arguments: {}, | ||
source: {}, | ||
stash: { | ||
current_user_id: 'someString', | ||
}, | ||
prevResult: { | ||
current_user_id: 'someString', | ||
}, | ||
}, | ||
{ | ||
headers: { Key: 'value' }, | ||
requestAuthorizationMode: AmplifyAppSyncSimulatorAuthenticationType.API_KEY, | ||
}, | ||
info, | ||
); | ||
expect(result.errors).toEqual([]); | ||
expect(result.result).toEqual('the same value'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters