You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if(testExists(exportsMetadata,testId))logAndExit(`Test with id ${testId} already generated, you can find it here: ${`./${EXPORTED_TESTS_DIR}/${exportsMetadata[testId].testName}`}. If you want to generate it again delete old one first.`);
139
+
95
140
lettest=generatedTests.find(t=>t.id===testId);
96
141
if(!test)thrownewError(`Test with id ${testId} not found`);
console.log(`Test with id ${testId} already generated, you can find it here: ${`./${EXPORTED_TESTS_DIR}/${exportsMetadata[testId].testName}`}.`);
151
+
continue;
152
+
}
153
+
103
154
lettestData=convertOldTestForGPT(test);
104
155
lettokens=getTokensInMessages([
105
156
{"role": "system","content": "You are a QA engineer and your main goal is to find ways to break the application you're testing. You are proficient in writing automated integration tests for Node.js API servers.\n"+
@@ -112,9 +163,12 @@ async function exportTest(originalTest) {
@@ -69,6 +69,18 @@ async function getJestTestFromPythagoraData(reqData) {
69
69
]);
70
70
}
71
71
72
+
asyncfunctiongetJestTestName(test,usedNames){
73
+
awaitgetOpenAIClient();
74
+
returnawaitcreateGPTChatCompletion([
75
+
{"role": "system","content": "You are a QA engineer and your main goal is to think of good, human readable jest tests file names. You are proficient in writing automated integration tests for Node.js API servers.\n"+
76
+
"When you respond, you don't say anything except the filename - no formatting, no explanation, no code - only filename.\n"},
In section <REPLACE_USERDOC_PASSWORD_WITH_DEFAULTUSEROBJ_PASSWORD> you should replace password from userDoc with defaultUser password so that login can always pass. Here is example, that should work in most cases, how to do that. Modify this example only if password is in other object key eg. userDoc.pass
83
+
```javascript
84
+
if (userDoc) userDoc.password = defaultUserObj.password;
85
+
```
86
+
87
+
<LOGIN_BODY> should always have same password as one I provided you as data that's sent in the request body during the login.
80
88
81
89
Input variables are:
82
90
1. appUrl - the URL of the app
83
91
2. userDoc - mongo document of the user that needs to be logged in for a specific test. Each test can require a different user to log in for the test to be successful. getAuthToken function needs to take that document and, before it inserts the document into the database, replace the password field with the password value captured in the data above so that we're always able to log the user in with the same password. If `userDoc` is undefined or invalid, you should use default userDoc which was provided above as `Mongo queries made during the execution of the login endpoint` you just have to find which is user document.
84
92
85
-
Don't modify userObj before this:
86
-
```javascript
87
-
if (!existingUser) {
88
-
await User.insertOne(userObj);
89
-
}
90
-
```
91
-
Document `userObj` should always be inserted to database with original values, especially any type of password or hash. After you checked for `existingUser` and inserted it to database, then you can modify it if needed.
92
-
93
93
When replacing <LOGIN_BODY> do not hardcode anything but use `userDoc`.
94
94
95
95
Don't require `global` because that is the native NodeJS global variable.
`preQueryDocs` and `postQueryDocs` are important so that you can test if an update in the database happened correctly so make sure to include in the test a check to see if the database was correctly updated. Also, since Mongo's `ObjectId` is not a valid JSON value, you might see a string like this - "ObjectId(\"642548c3dabd5517e39b5827\")". Keep in mind that this should be converted to `new ObjectId("642548c3dabd5517e39b5827")` and if you need to initiate ObjectId, you can require it from "mongodb" - like this:
27
+
`preQueryDocs` and `postQueryDocs` are important so that you can test if an update in the database happened correctly so make sure to include in the test a check to see if the database was correctly updated. Also, since Mongo's `ObjectId` is not a valid JSON value, sometimes you might see a string like this - "ObjectId(\"642548c3dabd5517e39b5827\")". Keep in mind that this should be converted to `new ObjectId("642548c3dabd5517e39b5827")` and if you need to initiate ObjectId, you can require it from "mongodb" - like this:
28
28
```javascript
29
29
const { ObjectId } = require("mongodb");
30
30
let someObjectId = new ObjectId(id);
@@ -36,7 +36,7 @@ Don't require `global` because that is the native NodeJS global variable.
36
36
37
37
If the database was updated, check if the database was updated correctly. When you need to make a query to a Mongo collection, use `global.getMongoCollection(collection)` function which will return the MongoDB collection which you can query how you want. For example, if you want to do a `find` query on a collection "users", you can do `global.getMongoCollection('users').find(query)`.
38
38
39
-
If you need to use the Mongo database for anything, add `let mongoDocuments = await global.setUpDb(testId);` to the beginning of the `beforeAll` function. You don't need to insert any documents in the database because all needed documents will be inserted in the `setUpDb` function. You can find the `testId` in the JSON request data that I will give you.
39
+
If you need to use the Mongo database for anything, add `let mongoDocuments = await global.setUpDb(testId);` to the beginning of the `beforeAll` function. You don't need to insert any documents in the database because all needed documents will be inserted in the `setUpDb` function. You can find the `testId` in the JSON request data that I will give you. Response from `await global.setUpDb(testId)` will be mongo document so if you use it you don't have to convert ObjectId as mentioned above.
40
40
The returned `mongoDocuments` variable is a JSON object that has a collection name as a key and an array of all documents in that collection that are present in the database as a value. The format of `mongoDocuments` object is this:
41
41
```json
42
42
{
@@ -120,7 +120,7 @@ beforeAll(async () => {
120
120
```
121
121
If you need to set some headers for test to be successful, set only necessary headers.
122
122
123
-
Response from `getAuthToken()` has to be stored in `authToken` variable and shouldn't be modified. This is the only correct way of adding token or cookie to header:
123
+
If authentication is needed, response from `getAuthToken()` has to be stored in `authToken` variable and shouldn't be modified. In that case, you shouldn't do anything else with `authToken` and you have to add it to headers only like this:
I will give you whole file that contains one or more Jest tests. I want you to think of good, meaningfull and human readable filename to store that test.
2
+
3
+
Filename you create should always end with `.test.js` as extension since this is jest test.
0 commit comments