package handlers

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
)

func TestECUPrioritySwap(t *testing.T){
	b := ManifestMigrateBody{
		MigratedManifest: common.UpdateManifest{
			ECUs:            []*common.UpdateManifestECU{{
				ID:                3,
				InstallPriority:   1,
			},
			{
				ID:                2,
				InstallPriority:   2,
			},
			{
				ID:                1,
				InstallPriority:   3,
			}},
		},
	}
	swapECUInstallPriority(&b)

	for _, ecu := range b.MigratedManifest.ECUs{
		if ecu.ID != int64(ecu.InstallPriority){
			t.Fail()
		}
	}

	b = ManifestMigrateBody{
		MigratedManifest: common.UpdateManifest{
			ECUs:            []*common.UpdateManifestECU{{
				ID:                4,
				InstallPriority:   1,
			},
			{
				ID:                3,
				InstallPriority:   2,
			},
			{
				ID:                2,
				InstallPriority:   3,
			},
			{
				ID:                1,
				InstallPriority:   4,
			},
		},
		},
	}
	swapECUInstallPriority(&b)
	for _, ecu := range b.MigratedManifest.ECUs{
		if ecu.ID != int64(ecu.InstallPriority){
			t.Fail()
		}
	}
}