import { describe, it, expect } from "vitest";
import { buildResource } from "./resource";
import {
  ATTR_SERVICE_NAME,
  ATTR_SERVICE_VERSION,
  ATTR_DEPLOYMENT_ENVIRONMENT_NAME,
} from "@opentelemetry/semantic-conventions/incubating";

describe("buildResource", () => {
  it("populates service name, version, and environment", () => {
    const r = buildResource({
      serviceName: "web-next",
      serviceVersion: "1.0.0",
      environment: "production",
    });
    expect(r.attributes[ATTR_SERVICE_NAME]).toBe("web-next");
    expect(r.attributes[ATTR_SERVICE_VERSION]).toBe("1.0.0");
    expect(r.attributes[ATTR_DEPLOYMENT_ENVIRONMENT_NAME]).toBe("production");
  });

  it("populates namespace when provided", () => {
    const r = buildResource({
      serviceName: "web-next",
      environment: "production",
      namespace: "template-vertical",
    });
    expect(r.attributes["service.namespace"]).toBe("template-vertical");
  });

  it("omits version and namespace when not provided", () => {
    const r = buildResource({
      serviceName: "web-next",
      environment: "production",
    });
    expect(r.attributes[ATTR_SERVICE_VERSION]).toBeUndefined();
    expect(r.attributes["service.namespace"]).toBeUndefined();
  });
});
