Common-SenseMakers / sensemakers

Sensemakers infrastructure for developing AI-based tools for semantic annotations of social posts. Cross-poster app to publish your semantic posts on different networks.
GNU General Public License v3.0
1 stars 2 forks source link

Feature/twitter access token refresh #35

Closed weswalla closed 4 months ago

weswalla commented 5 months ago

We can now use puppeteer to automatically go through the oauth authorization flow. However, it only seems to work if we run puppeteer NOT in headless mode (you will see a browser window open up and the information being put in to the form). It also takes ~10 seconds in total. image

You also need to store use credentials in the .env.test file, like so:

TEST_USER_TWITTER_CREDENTIALS={"sense_nets": {"user_id": "1742000911797366784", "username": "sense_nets", "password": "PASSWORD-HERE"},"sense_nets_bot": {"user_id": "1773032135814717440", "username": "sense_nets_bot","password": "PASSWORD-HERE"}}
weswalla commented 5 months ago

@pepoospina I am unable to run the tests fully since I am having issues with twitter developer account authentication (see discord message). But if all the tests pass I'd say this is ready to merge.

Note that I consolidated some environment variables, so now it expects TEST_USER_TWITTER_ACCOUNTS which looks like:

TEST_USER_TWITTER_ACCOUNTS=[{"user_id": "1773032135814717440", "username": "sense_nets_bot","password": "PASSWORD"}, {"user_id": "1742000911797366784", "username": "sense_nets", "password": "PASSWORD"}]

I included the user_id in the end so that we can use just this environment variable when created test app users (which need a userId). I no longer use TEST_USERS_BEARER_TOKENS

weswalla commented 5 months ago

This is also set up to be able to authenticate any number of twitter account that is specified in the environment variable along with the NUM_TWITTER_USERS constant.

pepoospina commented 5 months ago

@weswalla, a few suggestions here:

1) maybe we can change a bit the structure so that the authenticateTwitterUsers.ts is renamed to authenticate.users.ts and, instead of returning the TwitterUserDetails[], it returns already an array of type AppUserCreate[].

This way we handle entire user profiles and not just twitter credentials as the thing that is computed and stored on a file.

2) createTestAppUsers can receive a string[] with the userIds of the users that should be created. This way each test can decide which users are created that are relevant for them. Internally, createTestAppUsers will read the users objects for thos userIds from the global testTwitterAccountTokens map, which can be renamed to testUsers.

3) The files inside __test_support__ can be moved into utils and __test_support__ can be removed.

WDYT?

pepoospina commented 5 months ago

@weswalla, Also, I suggest we keep the file's naming convention to lowercase with dots :)

weswalla commented 5 months ago

Sure @pepoospina that all sounds good to me, I wasn't clear on conventions so just went ahead with this approach knowing we would change it with some feedback. Happy to use that file naming convention.

weswalla commented 5 months ago

@pepoospina I have integrated your feedback. The only things that remain (which could be handled in another PR) are: