Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote functions: Some processEvent unit tests #2203

Closed
wants to merge 2 commits into from

Conversation

filmaj
Copy link
Contributor

@filmaj filmaj commented Aug 14, 2024

No description provided.

@filmaj filmaj requested a review from misscoded August 14, 2024 17:48
@filmaj filmaj self-assigned this Aug 14, 2024
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.98%. Comparing base (0110bf2) to head (27d928d).

Additional details and impacted files
@@                Coverage Diff                 @@
##           feat-functions    #2203      +/-   ##
==================================================
+ Coverage           81.59%   82.98%   +1.39%     
==================================================
  Files                  19       19              
  Lines                1646     1646              
  Branches              464      465       +1     
==================================================
+ Hits                 1343     1366      +23     
+ Misses                194      178      -16     
+ Partials              109      102       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@misscoded misscoded left a comment

Choose a reason for hiding this comment

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

Couple of open questions to address/leave at your discretion. Thanks for taking the time to do these tests! 🙇🏼‍♀️

function_execution_id: 'Fx1234',
bot_access_token: 'xowfp',
},
function_data: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to double-check, but AFAIK, function_data only is associated with block_actions payloads – not function_executed.

{
  type: 'function_executed',
  function: {
    id: 'Fn0695V91LGN',
    callback_id: 'sample_function',
    title: 'Sample function 1',
    description: 'Runs sample function',
    type: 'app',
    input_parameters: [ [Object] ],
    output_parameters: [ [Object] ],
    app_id: 'A06A1C8C5FS',
    date_created: 1702069571,
    date_released: 0,
    date_updated: 1723658242,
    date_deleted: 0,
    form_enabled: false
  },
  inputs: { user_id: 'U019GD47LJH' },
  function_execution_id: 'Fx07HMB67Y3S',
  workflow_execution_id: 'Wx07GVLL7ZTP',
  event_ts: '1723658328.841355',
  bot_access_token: 'xwfp-444'
}

versus

{
  type: 'block_actions',
  team: { id: 'T019KFN8A2W', domain: 'misscoded' },
  enterprise: null,
  user: { id: 'U019GD47LJH', name: 'arenz', team_id: 'T019KFN8A2W' },
  channel: { id: 'D0699LNQ3HT', name: 'directmessage' },
  message: {
    user: 'U069CFDKS03',
    type: 'message',
    ts: '1723658484.749309',
    bot_id: 'B069F2HQSFN',
    app_id: 'A06A1C8C5FS',
    text: 'Click the button to signal the function has completed',
    team: 'T019KFN8A2W',
    blocks: [ [Object] ],
    assistant_app_thread: { title: '', title_blocks: [] }
  },
  container: {
    type: 'message',
    message_ts: '1723658484.749309',
    channel_id: 'D0699LNQ3HT',
    is_ephemeral: false
  },
  actions: [
    {
      block_id: 'I9kjf',
      action_id: 'sample_button',
      type: 'button',
      text: [Object],
      action_ts: '1723658488.667103'
    }
  ],
  api_app_id: 'A06A1C8C5FS',
  state: { values: {} },
  bot_access_token: 'xwfp-444',
  function_data: {
    execution_id: 'Fx07GVMA73NH',
    function: { callback_id: 'sample_function' },
    inputs: { user_id: 'U019GD47LJH' }
  },
  interactivity: {
    interactor: {
      secret: 'xxx',
      id: 'U019GD47LJH'
    },
    interactivity_pointer: '7576612985154.1325532282098.90f3e0899eaced8770aaf84abe894dcd'
  }
}

await fakeReceiver.sendEvent({
body: {
event: {
type: 'function_executed',
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about payloads above.

@@ -1624,8 +1624,8 @@ function extractFunctionContext(body: StringIndexed) {

// interactivity (block_actions)
if (body.function_data) {
functionExecutionId = body.function_data.execution_id;
functionBotAccessToken = body.bot_access_token;
functionExecutionId = body.function_data.execution_id || functionExecutionId;
Copy link
Contributor

@misscoded misscoded Aug 14, 2024

Choose a reason for hiding this comment

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

I don't follow the logic here: the two conditions never would happen in one go? body.event.type === 'function_executed' will never be true if body.function_data is also true, AFAIK, so the fallback would never be anything other than undefined.

@filmaj
Copy link
Contributor Author

filmaj commented Aug 14, 2024

Good call outs - the event payload processing happens in different spots (extractFunctionContext in app.ts, and enrichFunctionArgs in CustomFunction.ts), making unit tests for this problematic.

Going to close this PR but keep the branch around; the middleware system needs a desperate redesign anyways.

@filmaj filmaj closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants