Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/solapi/message/service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ defmodule Solapi.Message.Service do
|> maybe_add("kakaoOptions", get_field(message, :kakao_options, "kakaoOptions"))
|> maybe_add("rcsOptions", get_field(message, :rcs_options, "rcsOptions"))
|> maybe_add("customFields", get_field(message, :custom_fields, "customFields"))
|> maybe_add("faxOptions", get_field(message, :fax_options, "faxOptions"))
|> maybe_add("voiceOptions", get_field(message, :voice_options, "voiceOptions"))
Comment on lines +92 to +93

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

테스트 코드에서 제안된 스네이크 케이스 원자 키(:file_ids, :voice_type)를 API가 요구하는 카멜 케이스 문자열 키(fileIds, voiceType)로 변환하기 위해, 옵션 맵의 키를 변환하는 로직을 추가해야 합니다. 이렇게 하면 Elixir 코드베이스에서는 일관된 스네이크 케이스를 유지하면서 외부 API와의 연동을 원활하게 할 수 있습니다.

아래와 같이 키를 변환하는 함수를 호출하도록 변경하고, 해당 함수를 모듈 내에 비공개 함수로 추가하는 것을 제안합니다.

추가할 헬퍼 함수 예시:

defp transform_option_keys(nil), do: nil
defp transform_option_keys(map) when is_map(map) do
  for {key, val} <- map, into: %{} do
    {key |> Atom.to_string() |> to_camel_case(), val}
  end
end

defp to_camel_case(string) do
  [first | rest] = String.split(string, "_")
  first <> Enum.map_join(rest, "", &String.capitalize/1)
end

transform_option_keys/1 함수는 kakaoOptions, rcsOptions 등 다른 옵션에도 일관되게 적용하여 라이브러리 전반의 일관성을 높일 수 있습니다.

    |> maybe_add("faxOptions", get_field(message, :fax_options, "faxOptions") |> transform_option_keys())
    |> maybe_add("voiceOptions", get_field(message, :voice_options, "voiceOptions") |> transform_option_keys())

end

defp get_field(message, atom_key, string_key) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Solapi.MixProject do
use Mix.Project

@version "0.1.0"
@version "0.1.1"
@source_url "https://github.com/solapi/solapi-elixir"

def project do
Expand Down
62 changes: 62 additions & 0 deletions test/solapi/message/service_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,68 @@ defmodule Solapi.Message.ServiceTest do

assert {:error, %Solapi.Error.ValidationError{}} = result
end

test "FAX 메시지 발송 (faxOptions 포함)", %{bypass: bypass, client: client} do
Bypass.expect(bypass, "POST", "/messages/v4/send-many/detail", fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)
decoded = Jason.decode!(body)

message = hd(decoded["messages"])
assert message["to"] == "0212345678"
assert message["from"] == "0312345678"
assert message["faxOptions"]["fileIds"] == ["file_id_123", "file_id_456"]

response = %{
"groupId" => "G_FAX",
"messageId" => "M_FAX"
}

conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.resp(200, Jason.encode!(response))
end)

result =
Service.send(client, %{
to: "0212345678",
from: "0312345678",
fax_options: %{fileIds: ["file_id_123", "file_id_456"]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Elixir에서는 원자(atom) 키에 대해 스네이크 케이스(snake_case)를 사용하는 것이 일반적인 컨벤션입니다. :fileIds 대신 :file_ids를 사용하도록 변경하는 것이 좋겠습니다. 이 변경에 맞춰 Solapi.Message.Service.normalize_message/1 함수에서 중첩된 맵의 키를 카멜 케이스(camelCase)로 변환하는 로직 추가가 필요합니다. 이는 라이브러리 전체의 일관성을 높이고 Elixir 개발자에게 더 친숙한 인터페이스를 제공할 것입니다.

          fax_options: %{file_ids: ["file_id_123", "file_id_456"]}

})

assert {:ok, %{"messageId" => "M_FAX"}} = result
end

test "음성 메시지 발송 (voiceOptions 포함)", %{bypass: bypass, client: client} do
Bypass.expect(bypass, "POST", "/messages/v4/send-many/detail", fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)
decoded = Jason.decode!(body)

message = hd(decoded["messages"])
assert message["to"] == "01012345678"
assert message["from"] == "0212345678"
assert message["text"] == "음성 메시지 테스트입니다."
assert message["voiceOptions"]["voiceType"] == "FEMALE"

response = %{
"groupId" => "G_VOICE",
"messageId" => "M_VOICE"
}

conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.resp(200, Jason.encode!(response))
end)

result =
Service.send(client, %{
to: "01012345678",
from: "0212345678",
text: "음성 메시지 테스트입니다.",
voice_options: %{voiceType: "FEMALE"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Elixir의 컨벤션에 따라 원자(atom) 키는 스네이크 케이스(snake_case)로 작성하는 것이 좋습니다. :voiceType:voice_type으로 변경하는 것을 제안합니다. 이와 함께 Solapi.Message.Service 모듈에서 API 요청을 보내기 전에 이 키를 voiceType과 같은 카멜 케이스(camelCase) 문자열로 변환하는 로직이 필요합니다. 이는 FAX 옵션과 마찬가지로 코드의 일관성과 가독성을 향상시킵니다.

          voice_options: %{voice_type: "FEMALE"}

})

assert {:ok, %{"messageId" => "M_VOICE"}} = result
end
end

describe "send/1 with config" do
Expand Down