Skip to content

Commit

Permalink
test: add differ custom id spec
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 committed Nov 10, 2024
1 parent 0db8765 commit cf85b2e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/cli/src/differ/differv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ export class DifferV3 {
// Exists locally but not remotely: resource created by user
local.forEach(([localName, localId, localItem]) => {
if (checkedRemoteId.includes(localId)) return;

unset(localItem, 'metadata');
unset(localItem, 'id');

return result.push({
resourceType,
type: ADCSDK.EventType.CREATE,
Expand Down
70 changes: 70 additions & 0 deletions apps/cli/src/differ/specs/custom-id.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as ADCSDK from '@api7/adc-sdk';

import { DifferV3 } from '../differv3';

describe('Differ V3 - resources custom id', () => {
it('should delete and create new resource when update resource id (with nested resource)', () => {
const service1Name = 'Test Service 1';
const service1Id = ADCSDK.utils.generateId(service1Name);
const service2Name = 'Test Service 2';
const service2Id = ADCSDK.utils.generateId(service2Name);
const customId1 = 'custom-id-1';
const customId2 = 'custom-id-2';
expect(
DifferV3.diff(
{
services: [
{
id: customId1,
name: service1Name,
},
{
name: service2Name,
},
],
},
{
services: [
{
id: service1Id,
name: service1Name,
},
{
id: customId2,
name: service2Name,
},
],
},
),
).toEqual([
{
oldValue: { name: service1Name },
resourceId: service1Id,
resourceName: service1Name,
resourceType: ADCSDK.ResourceType.SERVICE,
type: ADCSDK.EventType.DELETE,
},
{
oldValue: { name: service2Name },
resourceId: customId2,
resourceName: service2Name,
resourceType: ADCSDK.ResourceType.SERVICE,
type: ADCSDK.EventType.DELETE,
},
{
newValue: { name: service1Name },
resourceId: customId1,
resourceName: service1Name,
resourceType: ADCSDK.ResourceType.SERVICE,
type: ADCSDK.EventType.CREATE,
},
{
newValue: { name: service2Name },
resourceId: service2Id,
resourceName: service2Name,
resourceType: ADCSDK.ResourceType.SERVICE,
type: ADCSDK.EventType.CREATE,
},
]);
});
});

0 comments on commit cf85b2e

Please sign in to comment.