@@ -743,6 +743,28 @@ describe('linking a claimed license', () => {
743743 } )
744744 } )
745745
746+ it ( 'starts the license usage at the first link and keeps it when the same organization links again' , async ( ) => {
747+ const fresh = await createClaimedLicense ( )
748+ entitlementsByLicense . set ( fresh . licenseArn , [ currentEntitlement ( ) ] )
749+ const before = Date . now ( )
750+
751+ await link ( ownerId , { licenseId : fresh . id , claimToken : fresh . token } )
752+
753+ const linkedAt = ( await readLicense ( fresh . licenseArn ) ) ?. organizationLinkedAt
754+ expect ( linkedAt ?. getTime ( ) ) . toBeGreaterThanOrEqual ( before - 1000 )
755+
756+ const firstLinkedAt = new Date ( Date . now ( ) - 5 * 60 * 60 * 1000 )
757+ const relinked = await createClaimedLicense ( {
758+ organizationId,
759+ organizationLinkedAt : firstLinkedAt ,
760+ } )
761+ entitlementsByLicense . set ( relinked . licenseArn , [ currentEntitlement ( ) ] )
762+
763+ await link ( ownerId , { licenseId : relinked . id , claimToken : relinked . token } )
764+
765+ expect ( ( await readLicense ( relinked . licenseArn ) ) ?. organizationLinkedAt ) . toEqual ( firstLinkedAt )
766+ } )
767+
746768 it ( 'refuses to move a license already linked to another organization' , async ( ) => {
747769 const otherOwnerId = await createUser ( )
748770 const otherOrganizationId = await createOrganization ( [ { userId : otherOwnerId , role : 'owner' } ] )
@@ -1457,10 +1479,20 @@ describe('license events across listings', () => {
14571479
14581480 expect ( await reconcileAwsMarketplaceLicenses ( ) ) . toMatchObject ( { applied : 1 , discarded : 0 } )
14591481 expect ( deleted ) . toEqual ( [ 'r-0' ] )
1460- expect ( await readLicense ( licenseArn ) ) . toMatchObject ( {
1461- status : 'inactive' ,
1462- dimension : 'platform' ,
1463- } )
1482+ const lapsed = await readLicense ( licenseArn )
1483+ expect ( lapsed ) . toMatchObject ( { status : 'inactive' , dimension : 'platform' } )
1484+ expect ( lapsed ?. endedAt ) . toBeInstanceOf ( Date )
1485+
1486+ deliverOnce ( [ licenseUpdated ( licenseArn , undefined , undefined , USAGE_PRODUCT ) ] )
1487+ await reconcileAwsMarketplaceLicenses ( )
1488+ expect ( ( await readLicense ( licenseArn ) ) ?. endedAt ) . toEqual ( lapsed ?. endedAt )
1489+
1490+ entitlementsByLicense . set ( licenseArn , [
1491+ currentEntitlement ( { ProductCode : USAGE_PRODUCT , Dimension : 'platform' } ) ,
1492+ ] )
1493+ deliverOnce ( [ licenseUpdated ( licenseArn , undefined , undefined , USAGE_PRODUCT ) ] )
1494+ await reconcileAwsMarketplaceLicenses ( )
1495+ expect ( await readLicense ( licenseArn ) ) . toMatchObject ( { status : 'active' , endedAt : null } )
14641496 } )
14651497} )
14661498
0 commit comments