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

Fix conversion bug #17

Merged
merged 1 commit into from
Feb 1, 2022
Merged

Fix conversion bug #17

merged 1 commit into from
Feb 1, 2022

Conversation

danielbdias
Copy link
Contributor

Motivation

Given we added a feature to use MongoDB to storage instead of Cassandra, we need to deal with changes of the typing that could occur on Mongo. On this MR we are changing the way how we Unmarshall messages to consider PlayerID as a number too. This PR extends the number checking on #16 .

Technical Debt

In the next releases, we need to think about how we can improve unmarshalling procedures for other message fields.

How to test it

Pre-requisites

  1. Start the database and populate MongoDB with make deps setup/mongo;
  2. Connect into mongoDB and run the following command:
> use chat

> db.messages.insertMany([
  {
    _id: ObjectId("61f18d6e901b304d707fd803"),
    id: 'urn:uuid:fe67bc4a-6517-4c96-a89d-09b7fe6e1e8e',
    player_id: 1,
    game_id: 'mygame',
    topic: 'chat/mygame/room/general',
    message: 'Hello World',
    timestamp: 1643220334,
    blocked: false,
    metadata: {
      blocked: false,
      Type: 1,
      Time: NumberLong("637788171338607270"),
      Sender: { PlayerId: 1, Name: 'Bob' },
      Message: 'Hello World',
      Mentions: [],
      Id: 'urn:uuid:fe67bc4a-6517-4c96-a89d-09b7fe6e1e8e',
      GameId: 'mygame'
    },
    should_moderate: true,
    original_payload: {
      blocked: false,
      Type: 1,
      Time: NumberLong("637788171338607270"),
      Sender: { PlayerId: 1, Name: 'Bob' },
      Message: 'Hello World',
      Mentions: [],
      Id: 'urn:uuid:fe67bc4a-6517-4c96-a89d-09b7fe6e1e8e',
      GameId: 'mygame'
    }
  },
  {
    _id: ObjectId("61f0f98027b114a532751e05"),
    id: 'urn:uuid:cf7711d6-95df-4be7-8b9a-6ecfb812c408',
    player_id: 'alice',
    game_id: 'myanothergame',
    topic: 'chat/myanothergame/room/general',
    message: 'Hi',
    timestamp: 1643182464,
    blocked: false,
    metadata: {
      blocked: false,
      Type: 1,
      Time: NumberLong("637787792628932950"),
      Sender: { PlayerId: 'alice', Name: 'Alice' },
      Message: 'Hi',
      Mentions: [],
      Id: 'urn:uuid:cf7711d6-95df-4be7-8b9a-6ecfb812c408',
      GameId: 'myanothergame'
    },
    should_moderate: true,
    original_payload: {
      blocked: false,
      Type: 1,
      Time: NumberLong("637787792628932950"),
      Sender: { PlayerId: 'alice', Name: 'Alice' },
      Message: 'Hi',
      Mentions: [],
      Id: 'urn:uuid:cf7711d6-95df-4be7-8b9a-6ecfb812c408',
      GameId: 'myanothergame'
    }
  }
])
  1. Start the API with make run.

Test cases

Retrieving messages from games that have PlayerId as a number

  • Given I am an API consumer
  • When I try to query my game messages
curl --location --request GET 'http://localhost:8888/history/chat/mygame/room/general?userid=mygame:metagame-mygame&limit=1000'
  • Then I should return JSON array with my messages
# you should see an array with one message from Bob
  • And no warning log should be triggered API output

Retrieving messages from games that have PlayerId as a string

  • Given I am an API consumer
  • When I try to query my game messages
curl --location --request GET 'http://localhost:8888/history/chat/myanothergame/room/general?userid=myanothergame:metagame-myanothergame&limit=1000'
  • Then I should return JSON array with my messages
# you should see an array with one message from Alice
  • And no warning log should be triggered API output

@coveralls
Copy link

Coverage Status

Coverage remained the same at 75.082% when pulling 5c574ab on fix/conversion-bug into cc070c0 on master.

@danielbdias danielbdias merged commit dc7b570 into master Feb 1, 2022
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.

None yet

2 participants