Skip to content

Commit 4893aa2

Browse files
CP-14193 Add external_id persistence tests
What Adds test coverage confirming DocuSeal already persists the submitter `external_id` field end-to-end — through both the service layer and the API request path. No production code changes. Why ATS will now send `external_id` (`ats-user-<id>`) on every submitter so it can match submitters by stable user id instead of mutable email. These tests pin DocuSeal's existing pass-through behavior so it cannot regress silently. How to test bundle exec rspec spec/lib/submissions/create_from_submitters_spec.rb \ spec/requests/submissions_spec.rb
1 parent bf48144 commit 4893aa2

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

spec/lib/submissions/create_from_submitters_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,34 @@ def call(template:, submitters_order:)
9292
expect(submitter_uuids).not_to include(template.submitters[1]['uuid'])
9393
end
9494
end
95+
96+
describe 'external_id' do
97+
let(:attrs_with_external_id) do
98+
template.submitters.map.with_index do |s, index|
99+
{ 'uuid' => s['uuid'], 'email' => Faker::Internet.email,
100+
'external_id' => "ats-user-#{index + 1}" }.with_indifferent_access
101+
end
102+
end
103+
104+
it 'persists external_id provided on each submitter' do
105+
submissions = described_class.call(
106+
template:,
107+
user:,
108+
submissions_attrs: [{ 'submitters' => attrs_with_external_id }.with_indifferent_access],
109+
source: :api,
110+
submitters_order: 'simultaneous'
111+
)
112+
113+
persisted = submissions.first.submitters.sort_by do |s|
114+
template.submitters.index { |ts| ts['uuid'] == s.uuid }
115+
end
116+
expect(persisted.map(&:external_id)).to eq(%w[ats-user-1 ats-user-2])
117+
end
118+
119+
it 'leaves external_id blank when not provided' do
120+
submissions = call(template:, submitters_order: 'simultaneous')
121+
122+
expect(submissions.first.submitters.map(&:external_id)).to all(be_nil)
123+
end
124+
end
95125
end

spec/requests/submissions_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@
139139
expect(response.parsed_body[1]['email']).to eq('jane.doe@example.com')
140140
end
141141

142+
it 'persists external_id passed on each submitter' do
143+
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
144+
template_id: templates[0].id,
145+
send_email: true,
146+
submitters: [{ role: 'Employee', email: 'john.doe@example.com', external_id: 'ats-user-42' }]
147+
}.to_json
148+
149+
expect(response).to have_http_status(:ok)
150+
expect(Submission.last.submitters.first.external_id).to eq('ats-user-42')
151+
end
152+
142153
it 'returns an error if the submitter email is invalid' do
143154
post '/api/submissions', headers: { 'x-auth-token': author.access_token.token }, params: {
144155
template_id: templates[0].id,

0 commit comments

Comments
 (0)