package com.foxx.androidcast.network;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class BackendEndpointsTest {
    @Test
    public void canonicalUrlsUseAppsHost() {
        assertTrue(BackendEndpoints.HEARTBEAT_URL.startsWith("https://apps.f0xx.org/"));
        assertTrue(BackendEndpoints.UPLOAD_URL.contains("/issues/api/upload.php"));
        assertTrue(BackendEndpoints.ENTITLEMENTS_FETCH_URL.contains("/entitlements/api/fetch.php"));
    }

    @Test
    public void normalizeCrashesUrlRewritesLegacyHost() {
        String legacy = "https://f0xx.org/app/androidcast_project/crashes/api/upload.php";
        assertEquals(BackendEndpoints.UPLOAD_URL, BackendEndpoints.normalizeCrashesUrl(legacy));
    }

    @Test
    public void graphUploadUrlFromCrashesUrl() {
        assertEquals(BackendEndpoints.GRAPH_UPLOAD_URL,
                BackendEndpoints.graphUploadUrlFromCrashesUrl(BackendEndpoints.UPLOAD_URL));
    }
}
