@mindful-web/marko-web-omeda-identity-x 1.106.1 → 1.107.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
- marko_componentType = "/@mindful-web/marko-web-omeda-identity-x$1.106.1/components/identify.marko",
5
+ marko_componentType = "/@mindful-web/marko-web-omeda-identity-x$1.107.1/components/identify.marko",
6
6
  marko_component = require("./identify.marko"),
7
7
  marko_renderer = require("marko/dist/runtime/components/renderer"),
8
8
  module_getCookieId = require("@mindful-web/marko-web-omeda-identity-x/utils/get-cookie-id"),
@@ -51,7 +51,7 @@ marko_template._ = marko_renderer(render, {
51
51
  }, marko_component);
52
52
 
53
53
  marko_template.meta = {
54
- id: "/@mindful-web/marko-web-omeda-identity-x$1.106.1/components/identify.marko",
54
+ id: "/@mindful-web/marko-web-omeda-identity-x$1.107.1/components/identify.marko",
55
55
  component: "./identify.marko",
56
56
  tags: [
57
57
  "@mindful-web/marko-web-identity-x/components/identify.marko",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindful-web/marko-web-omeda-identity-x",
3
- "version": "1.106.1",
3
+ "version": "1.107.1",
4
4
  "description": "Marko Omeda+IdentityX integration tools",
5
5
  "repository": "https://github.com/parameter1/mindful-web/tree/main/packages/marko-web-omeda-identity-x",
6
6
  "author": "Josh Worden <josh@parameter1.com>",
@@ -33,5 +33,5 @@
33
33
  "chai": "^4.3.7",
34
34
  "mocha": "^6.2.3"
35
35
  },
36
- "gitHead": "a7a90d04e081aac7c14a326e9a40dc63e43569d1"
36
+ "gitHead": "53223059709e01a61635206e5f2f319896c359d3"
37
37
  }
package/rapid-identify.js CHANGED
@@ -125,7 +125,26 @@ module.exports = async (params = {}) => {
125
125
  }).map((select) => {
126
126
  const { field } = select;
127
127
  const { identifier } = field.externalId;
128
- const writeInValue = select.answers.reduce((v, answer) => (v || answer.writeInValue), null);
128
+ // A write-in is only sent for an option that currently accepts one. Omeda rejects the WHOLE
129
+ // rapid identification when `WriteInDesc` accompanies a value whose type is not "Other", and
130
+ // stored answers can carry write-ins the option no longer allows (e.g. text kept from before
131
+ // an option's write-in support was removed). When the field's options aren't on the user,
132
+ // nothing is known about them and the write-in passes through as before.
133
+ const writeInAllowed = (() => {
134
+ const options = getAsArray(field, 'options');
135
+ if (!options.length) return () => true;
136
+ const ids = new Set();
137
+ options.forEach((option) => {
138
+ if (option.canWriteIn) ids.add(`${option.id}`);
139
+ getAsArray(option, 'options').forEach((child) => {
140
+ if (child.canWriteIn) ids.add(`${child.id}`);
141
+ });
142
+ });
143
+ return (answer) => ids.has(`${answer.id}`);
144
+ })();
145
+ const writeInValue = select.answers.reduce((v, answer) => (
146
+ v || (writeInAllowed(answer) ? answer.writeInValue : null)
147
+ ), null);
129
148
  return {
130
149
  id: parseInt(identifier.value, 10),
131
150
  values: select.answers.map((answer) => answer.externalIdentifier).filter((v) => v),
@@ -174,6 +174,58 @@ describe('rapid-identify (idx → omeda payload)', () => {
174
174
  });
175
175
  });
176
176
 
177
+ describe('select write-ins', () => {
178
+ // AQUA "Business Type - New": the stored answer carries a write-in, but option 343 is a
179
+ // None-of-the-above value in Omeda and no longer accepts one.
180
+ const writeInSelect = ({ options, answerId = 'opt-other' } = {}) => ({
181
+ id: 'business',
182
+ hasAnswered: true,
183
+ answers: [{ id: answerId, externalIdentifier: '343', writeInValue: 'Manufacture' }],
184
+ field: {
185
+ id: 'business',
186
+ active: true,
187
+ externalId: {
188
+ id: `omeda.demographic.${BRAND}*67`,
189
+ namespace: { provider: 'omeda', tenant: BRAND, type: 'demographic' },
190
+ identifier: { value: '67', type: null },
191
+ },
192
+ ...(options && { options }),
193
+ },
194
+ });
195
+
196
+ it('drops a stored write-in when its option does not accept one', async () => {
197
+ const payload = await run({
198
+ customSelectFieldAnswers: [writeInSelect({
199
+ options: [{ id: 'opt-build', canWriteIn: false }, { id: 'opt-other', canWriteIn: false }],
200
+ })],
201
+ });
202
+ expect(payload.demographics).to.deep.equal([{ id: 67, values: ['343'] }]);
203
+ });
204
+
205
+ it('sends the write-in when its option accepts one', async () => {
206
+ const payload = await run({
207
+ customSelectFieldAnswers: [writeInSelect({
208
+ options: [{ id: 'opt-other', canWriteIn: true }],
209
+ })],
210
+ });
211
+ expect(payload.demographics).to.deep.equal([{ id: 67, values: ['343'], writeInValue: 'Manufacture' }]);
212
+ });
213
+
214
+ it('honours canWriteIn on options nested in a group', async () => {
215
+ const payload = await run({
216
+ customSelectFieldAnswers: [writeInSelect({
217
+ options: [{ id: 'group', options: [{ id: 'opt-other', canWriteIn: true }] }],
218
+ })],
219
+ });
220
+ expect(payload.demographics[0].writeInValue).to.equal('Manufacture');
221
+ });
222
+
223
+ it('passes the write-in through when the field options are not on the user', async () => {
224
+ const payload = await run({ customSelectFieldAnswers: [writeInSelect()] });
225
+ expect(payload.demographics[0].writeInValue).to.equal('Manufacture');
226
+ });
227
+ });
228
+
177
229
  describe('payload validation (the contract is enforced, not assumed)', () => {
178
230
  const expectRejects = async (opts, match) => {
179
231
  try {