package org.whoneedhelp.mobile;

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

import org.junit.Test;

public final class LaunchUrlResolverTest {
    private final TrustedOrigin origin =
        TrustedOrigin.parse("https://help.example", false);

    @Test
    public void releaseAcceptsOnlySameOriginDeepLinks() {
        assertEquals(
            "https://help.example/requests/123",
            LaunchUrlResolver.incomingUrl(
                origin,
                "https://help.example/requests/123",
                null,
                false
            )
        );
        assertNull(
            LaunchUrlResolver.incomingUrl(
                origin,
                "https://attacker.example/requests/123",
                null,
                false
            )
        );
    }

    @Test
    public void releaseIgnoresDebugInitialUrlExtra() {
        assertEquals(
            "https://help.example",
            LaunchUrlResolver.initialUrl(
                origin,
                null,
                "https://help.example/requests/123",
                false
            )
        );
    }

    @Test
    public void debugCanUseValidatedInitialUrlExtra() {
        assertEquals(
            "https://help.example/requests/123",
            LaunchUrlResolver.initialUrl(
                origin,
                null,
                "https://help.example/requests/123",
                true
            )
        );
    }
}
