11import { UpdateModel } from '../../../test/models'
22import { Metadata , metadataForClass } from '../../decorator/metadata'
33import { createKeyAttributes } from '../../mapper'
4- import { update } from '../expression/logical-operator/update.function'
4+ import { update2 } from '../expression/logical-operator/update.function'
55import { getTableName } from '../get-table-name.function'
66import { TransactUpdate } from './transact-update'
77
88describe ( 'TransactUpdate' , ( ) => {
99 let op : TransactUpdate < UpdateModel >
1010 let metadata : Metadata < UpdateModel >
11+ let now : Date
1112 beforeEach ( ( ) => {
1213 op = new TransactUpdate ( UpdateModel , 'myId' )
14+ now = new Date ( )
1315 metadata = metadataForClass ( UpdateModel )
1416 } )
1517
16- it ( 'correct transactItem' , ( ) => {
17- const now = new Date ( )
18- op . operations ( update < UpdateModel > ( 'lastUpdated' ) . set ( now ) )
19- op . onlyIfAttribute ( 'name' ) . eq ( 'Foo Bar' )
20-
18+ afterEach ( ( ) => {
2119 expect ( op . transactItem ) . toEqual ( {
2220 Update : {
2321 TableName : getTableName ( UpdateModel ) ,
2422 Key : createKeyAttributes ( metadata , 'myId' ) ,
2523
26- UpdateExpression : 'SET #lastUpdated = :lastUpdated' ,
24+ UpdateExpression : 'SET #lastUpdated = if_not_exists(#lastUpdated, :lastUpdated) ' ,
2725 ConditionExpression : '#name = :name' ,
2826
2927 ExpressionAttributeNames : {
@@ -37,4 +35,17 @@ describe('TransactUpdate', () => {
3735 } ,
3836 } )
3937 } )
38+
39+ it ( 'correct transactItem [operations]' , ( ) => {
40+ op . operations ( update2 ( UpdateModel , 'lastUpdated' ) . set ( now , true ) )
41+ . onlyIfAttribute ( 'name' )
42+ . eq ( 'Foo Bar' )
43+ } )
44+
45+ it ( 'correct transactItem [updateAttribute]' , ( ) => {
46+ op . updateAttribute ( 'lastUpdated' )
47+ . set ( now , true )
48+ . onlyIfAttribute ( 'name' )
49+ . eq ( 'Foo Bar' )
50+ } )
4051} )
0 commit comments