const { BakongKHQR, SourceInfo } = require("../src");

const testData = [
    {
        statement: "Invalid DeepLink URL",
        data: [
            "https://sit-api-bakong.nbc.org.kh/deeplink",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
        ],
        errorCode: 29,
    },
    {
        statement: "Null callback source info",
        data: [
            "https://sit-api-bakong.nbc.org.kh/v1/generate_deeplink_by_qr",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
            new SourceInfo(
                "https://sit-api-bakong.nbc.org.kh/khqr.png",
                "KHQR",
                null
            ),
        ],
        errorCode: 14,
    },
    {
        statement: "Null icon source info",
        data: [
            "https://sit-api-bakong.nbc.org.kh/v1/generate_deeplink_by_qr",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
            new SourceInfo(
                null,
                "KHQR",
                "https://sit-api-bakong.nbc.org.kh/callback"
            ),
        ],
        errorCode: 14,
    },
    {
        statement: "Null name source info",
        data: [
            "https://sit-api-bakong.nbc.org.kh/v1/generate_deeplink_by_qr",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
            new SourceInfo(
                "https://sit-api-bakong.nbc.org.kh/khqr.png",
                null,
                "https://sit-api-bakong.nbc.org.kh/callback"
            ),
        ],
        errorCode: 14,
    },
    {
        statement: "Invalid QR",
        data: [
            "https://sit-api-bakong.nbc.org.kh/v1/generate_deeplink_by_qr",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF35",
        ],
        errorCode: 8,
    },
    {
        statement: "Deeplink timeout",
        data: [
            "http://13.251.28.10:80/v1/generate_deeplink_by_qr",
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
        ],
        errorCode: 13,
    },
    {
        statement: "Generating DeepLink successfully",
        data: [
            process.env.DEEP_LINK_URL,
            "00020101021229190015john_smith@devb5204599953038405405100.05802KH5910John Smith6010Phnom Penh6304BF30",
        ],
        errorCode: 0,
    },
];

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

testData.forEach((data) => {
    test(data.statement, () => {
        const decodeResponse = BakongKHQR.generateDeepLink(
            data.data[0],
            data.data[1],
            data.data[2]
        );
        decodeResponse.then((resp) =>
            expect(resp.status.errorCode).toBe(data.errorCode)
        );
    });
});
