All files / app/codeCharta/ui/customConfigs/downloadCustomConfigsButton downloadCustomConfigHelper.ts

100% Statements 9/9
100% Branches 0/0
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  7x 7x 7x               7x 7x   7x 1x           1x 1x    
import { ExportCustomConfig } from "../../../model/customConfig/customConfig.api.model"
import { FileNameHelper } from "../../../util/fileNameHelper"
import { FileDownloader } from "../../../util/fileDownloader"
import { stateObjectReplacer } from "../../../codeCharta.model"
 
interface CustomConfigsDownloadFile {
    downloadApiVersion: string
    timestamp: number
    customConfigs: Map<string, ExportCustomConfig>
}
 
const CUSTOM_CONFIG_FILE_EXTENSION = ".cc.config.json"
const CUSTOM_CONFIGS_DOWNLOAD_FILE_VERSION = "1.0.1"
 
export function downloadCustomConfigs(customConfigs: Map<string, ExportCustomConfig>) {
    const customConfigsDownloadFile: CustomConfigsDownloadFile = {
        downloadApiVersion: CUSTOM_CONFIGS_DOWNLOAD_FILE_VERSION,
        timestamp: Date.now(),
        customConfigs
    }
 
    const fileName = FileNameHelper.getNewTimestamp() + CUSTOM_CONFIG_FILE_EXTENSION
    FileDownloader.downloadData(JSON.stringify(customConfigsDownloadFile, stateObjectReplacer), fileName)
}