diff --git a/graphql/schema.graphql b/graphql/schema.graphql index f1c7c40..6b77359 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -27,6 +27,7 @@ type Node { name: String! groupId: ID domain: String # 所属しているdomain + expiresAt: AWSDateTime heartbeatIntervalSeconds: Int } diff --git a/js/functions/joinGroupFunction.js b/js/functions/joinGroupFunction.js index d889496..72871e1 100644 --- a/js/functions/joinGroupFunction.js +++ b/js/functions/joinGroupFunction.js @@ -64,12 +64,14 @@ export function response(ctx) { // TransactWriteItemsは個別のアイテムを返さないため、 // リクエストパラメータからNode型を構築 const { groupId, domain, nodeId } = ctx.args; + const group = ctx.stash.group; return { id: nodeId, name: `Node ${nodeId}`, groupId: groupId, domain: domain, + expiresAt: group ? group.expiresAt : null, heartbeatIntervalSeconds: +(ctx.env.MESH_MEMBER_HEARTBEAT_INTERVAL_SECONDS || '120') }; } diff --git a/spec/fixtures/mutations/join_group.graphql b/spec/fixtures/mutations/join_group.graphql index f67b1f3..de415ba 100644 --- a/spec/fixtures/mutations/join_group.graphql +++ b/spec/fixtures/mutations/join_group.graphql @@ -4,6 +4,7 @@ mutation JoinGroup($groupId: ID!, $domain: String!, $nodeId: ID!) { name groupId domain + expiresAt heartbeatIntervalSeconds } } diff --git a/spec/requests/join_group_expires_at_spec.rb b/spec/requests/join_group_expires_at_spec.rb new file mode 100644 index 0000000..a946cf1 --- /dev/null +++ b/spec/requests/join_group_expires_at_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" +require "time" + +RSpec.describe "joinGroup expiresAt validation", type: :request do + let(:timestamp) { (Time.now.to_f * 1000).to_i } + let(:domain) { "test-join-expires-at-#{timestamp}.example.com" } + let(:host_id) { "host-#{timestamp}" } + let(:node_id) { "node-#{timestamp}" } + let(:group_name) { "Join Group expiresAt Test" } + + it "joinGroup mutation returns expiresAt" do + # 1. グループを作成 + group = create_test_group(group_name, host_id, domain) + group_id = group["id"] + group_expires_at = group["expiresAt"] + expect(group_id).not_to be_nil + expect(group_expires_at).to match_iso8601 + + # 2. グループに参加 + join_response = join_test_node(group_id, domain, node_id) + + # 3. expiresAtが返されることを確認 + expect(join_response["expiresAt"]).not_to be_nil + expect(join_response["expiresAt"]).to match_iso8601 + + # 4. グループのexpiresAtと一致することを確認 + # AWSDateTimeのフォーマットが微妙に異なる可能性(ミリ秒の有無など)を考慮し、 + # Timeオブジェクトに変換して比較する + group_time = Time.parse(group_expires_at) + join_time = Time.parse(join_response["expiresAt"]) + expect(join_time).to eq(group_time) + end +end