Write TypeScript scripts interacting with Google Forms#9
For Google forms only with OAUTH 2.0 we can interact. Should I use https://www.npmjs.com/package/@googleapis/ ? @Hugo
42 Replies
like explained in the readme, do not include the oauth logic in the script, this is handled by windmill
the access token will be passed to the resource as the
token
property
so you can directly query the google api with itOkay, then I should use
token
as env. windwill will handle oauth and return that token that is necessary. Correct me if I'm wrongit's right
the only thing is you have to find a way to do the oauth flow locally to get a token to test your scripts
Raised a PR. Can you review it please?
@Hugo Can I change all the return to res.data to return the updated/created form
yes
And remove this part in all the tests?
Becuase forms is returned na
response should be checked to match what you wanted to created (e.g. the form title / fields)
and then you need to try to get the form and check that it exists
Okay got it, will update the PR in sometime
I am not sure what to do in setup.ts. Can you help me with that
@Hugo
Updated the rest of the files
you should create the form you use in the tests
Thats it in setup.ts right
yes
WIll remove the createForm const as well
this will be run before all tests
but you need to pass the form id to your tests
probably by setting the environment variable in setup.ts as well
in the tests you also have to query the api to check
will this const formId be used everywhere in tests if I specify in this way?
no you need to save it as an env variable
the createForm has formId how to pass that to tests
I think
resourse.formId can be used to store the formId and reponseId what do you say?
@Hugo
no
use environment variables
=> Bun.env.FORM_ID =
Got it
you can do inside setup.ts beforeAll
Okay got it
@Hugo Made all the changes. Let me know if I missed something
i'll have a look, did you run all tests and checked that they pass?
No, how can I get the token
Most probably everything shoudl run correctly tested the apis externally and used the same conf
Hey i've had a look:
- the Create_Text_question must take a title, description and paragraph (bool) arguments as well
- in Update_Form_Title you should check by a query to the api whether the form really has the new name
- in List_form_responses you should check that the length of responses is 0
- test your work (you can use https://developers.google.com/oauthplayground/ to get a token)
- fill in the readme with credentials instructions
OAuth 2.0 Playground
The OAuth 2.0 Playground lets you play with OAuth 2.0 and the APIs that supports it.
Will update the PR and let you know
in List_form_response when there is no response the api returns
{}
empty object
when access_token that is generated from playground is passed to auth. I'm getting Login Required error
@Hugodid you grant the right permissions for the token?
Yeah
@Hugo
Fixed the authentication part
Tests are failing will fix them by EOD
@Hugo
FORM_ID can be taken from the object after a form is created. But without submitting response to the form. It is not possible to get the RESPONSE_ID. What could be done in this case?
I have made some changes to the PR. Please check once
It would be nice if we could skip tests that require RESPONSE_ID
Just put instructions as comments inside the test
How can I execute a test individually?
Tests are executed in random order when FORM_ID and RESPONSE_ID are not even generated
And fails
i'm not sure i follow, but you should be able to setup what you need in setup.ts so that the tests work in any order
or directly into each test file
To be clear the problem is, only if create form is executed first we'll have FORM_ID for rest. Same applies for RESPONSE_ID after list response is executed.
So test cases can't be passed due to this. Can I comment out assertion on all tests so that test case won't fail?
that's why you should create the form in setup.ts
or in each test create a form
Okay I'll try either of these and get back with a result
@Hugo Finally completed!
Pushed everything. Please review it once
will have a look thanks
@Hugo Have you checked my PR?
done it's merged ! thanks for your contribution!
Thanks for the opportunity. Btw it's a great project. Will continue contributing ✨