// This file was auto-generated by Fern from our API Definition.

import * as Intercom from "../../src/api/index";
import { IntercomClient } from "../../src/Client";
import { mockServerPool } from "../mock-server/MockServerPool";

describe("PhoneCallRedirectsClient", () => {
    test("create (1)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            phone: "+353832345678",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = { type: "phone_call_redirect", phone: "+1 1234567890" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.phoneCallRedirects.create({
            phone: "+353832345678",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "phone_call_redirect",
            phone: "+1 1234567890",
        });
    });

    test("create (2)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            phone: "+353832345678",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = { type: "phone_call_redirect", phone: "+1 1234567890" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.phoneCallRedirects.create({
            phone: "+353832345678",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "phone_call_redirect",
            phone: "+1 1234567890",
        });
    });

    test("create (3)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            phone: "+353832345678",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = { type: "phone_call_redirect", phone: "+1 1234567890" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.phoneCallRedirects.create({
            phone: "+353832345678",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "phone_call_redirect",
            phone: "+1 1234567890",
        });
    });

    test("create (4)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });
        const rawRequestBody = {
            phone: "+40241100100",
            custom_attributes: { issue_type: "Billing", priority: "High" },
        };
        const rawResponseBody = { type: "phone_call_redirect", phone: "+1 1234567890" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .jsonBody(rawRequestBody)
            .respondWith()
            .statusCode(200)
            .jsonBody(rawResponseBody)
            .build();

        const response = await client.phoneCallRedirects.create({
            phone: "+40241100100",
            custom_attributes: {
                issue_type: "Billing",
                priority: "High",
            },
        });
        expect(response).toEqual({
            type: "phone_call_redirect",
            phone: "+1 1234567890",
        });
    });

    test("create (5)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .respondWith()
            .statusCode(400)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.phoneCallRedirects.create(undefined);
        }).rejects.toThrow(Intercom.BadRequestError);
    });

    test("create (6)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { type: "error.list", errors: [{ code: "code" }, { code: "code" }] };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .respondWith()
            .statusCode(401)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.phoneCallRedirects.create(undefined);
        }).rejects.toThrow(Intercom.UnauthorizedError);
    });

    test("create (7)", async () => {
        const server = mockServerPool.createServer();
        const client = new IntercomClient({
            maxRetries: 0,
            token: "test",
            version: "2.14",
            environment: server.baseUrl,
        });

        const rawResponseBody = { key: "value" };
        server
            .mockEndpoint()
            .post("/phone_call_redirects")
            .respondWith()
            .statusCode(422)
            .jsonBody(rawResponseBody)
            .build();

        await expect(async () => {
            return await client.phoneCallRedirects.create(undefined);
        }).rejects.toThrow(Intercom.UnprocessableEntityError);
    });
});
