"Reaction does not exist" when I want to delete a reaction - getstream-io
When writing my tests in Laravel with the Get Stream Laravel wrapper, I want to test to deleting a reaction.
I basically do this:
$client = FeedManager::getClient();
$reactions = $client->reactions()->filter('user_id' , $this->user->id);
$client->reactions()->delete($reactions['results'][0]['id']);
The result is this:
GuzzleHttp\Exception\ClientException: Client error: `DELETE https://api.stream-io-api.com/api/v1.0/reaction/e9a919f2-2e28-4c5d-889e-c5f60b5880e9/` resulted in a `404 Not Found` response:
{"detail":"Reaction does not exist","status_code":404,"code":16,"exception":"DoesNotExistException","duration":"1.69ms"}
I can confirm $reactions is not empty and give me a valid response.
In my base application it works as expected, but my test is failing for some reason.
What could be wrong?
Related
Cannot read properties of null (reading ‘data’)
This is what the error looks like I tried to run a command on my discord bot (I have a language system for it and that’s from where i think the error came from), then my bot crashed then sent that error message in console I thought it would work like it normally does but the bot just continues to crash everytime i run that command. The part where the error came from according to console: const guild_settings = require('../database/models/guild-settings.js'); const findLang = await guild_settings.findOne({ guild: interaction.guild.id }); const lang = require(`../langs/${findLang.data.language || "en"}.js`);
'FIRESTORE INTERNAL ASSERTION FAILED: Unexpected state' when unit testing with Jest
I'ḿ setting up a jest test suite for a Node.js and Express REST API i'm building, i'm using #firebase/testing module to initialize a testing app, however when i try to perform any sort of operation to the database this error comes out: FIRESTORE (7.17.2) INTERNAL ASSERTION FAILED: Unexpected state at fail (/home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/util/assert.ts:39:9) at hardAssert (/home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/util/assert.ts:53:5) at fromBytes (/home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/remote/serializer.ts:270:5) at fromWatchChange (/home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/remote/serializer.ts:486:25) at PersistentListenStream.onMessage (/home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/remote/persistent_stream.ts:576:25) at /home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/remote/persistent_stream.ts:456:21 at /home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/remote/persistent_stream.ts:509:18 at /home/cardonapablo/Documentos/Proyectos/Optica (Ilicit)../../../../../node_modules/#firebase/testing/node_modules/#firebase/firestore/src/util/async_queue.ts:369:14 I also tried connecting to my regular firestore database with the credentials i have been using to develop the endpoints and same error pops out even tho it's the app i use daily Weird thing is, data is being written to the database, but error still stops testing Here is firebase setup: (src/db/functions.js) let app = initializeTestApp({ projectId: "illicit" }) db = app.firestore() module.exports = { db } Function throwing the error (tests/fixtures/db.js) const { db } = require('../../src/db/functions') const bcrypt = require('bcrypt'); const createAdmin = async function() { // Encrypt password let encPass = await bcrypt.hash("admin", 8) let admin = { name: "Admin Test User", email: "admin#test.com", password: encPass, tokens: [] } // Add to db let docRef = await db.collection('admins').add(admin) // <- This line throws the error return; } module.exports = { createAdmin } And finally testing file (tests/glasses.test.js) const supertest = require('supertest'); const app = require('../src/app') const functions = require('./fixtures/db') let adminToken; let glassesId; //Executes before any test, here is where error occurs, before any tests beforeAll( async () => { await functions.createAdmin() return }) test('Should log in an admin', async () => { let response = await supertest(app) .post('/admins/login') .send({ email: 'admin#test.com', password: 'admin' }) .expect(200); expect(response.body.token).toEqual(expect.any(String)) adminToken = response.token; }); This only happens only when i try to test, regular app works just fine Things i've tried: Firestore rules are read and write true, so it's not a rules error Mocked Firestore with firebase-mock and Jest seems to work fine, however this is not a solution, since i need to test data inside the database Hope you can help me :)
You should change Jest's test environment from the default jsdom to node using jest --env=node or by setting the testEnvironment option to node in your Jest config.
Solved the problem myself, i was using the Firebase web client, I switched to the Admin SDK made specifically for servers, i guess it was some sort of auth problem, because the admin sdk automatically authenticates you in the db
This is a open issue on GitHub. I'm pasting my comment from that issue here to hopefully help some other people: I experienced the same error message on 9.6.6 with NextJS. I believe this error message could be presented due to a range of errors - as I see 100+ Stackoverflow questions with this error message. After lots of debugging I realized I accidently used SQL capitalization: .orderBy('time', 'ASC') = "INTERNAL ASSERTION FAILED: Unexpected state" .orderBy('time', 'asc') = No Errors! This was a pain to debug, and my mistake was so small. Maybe better error reporting is needed in cases like this? When you get then Google this error message it easily leads you down a path of debugging things completely irrelevant to the real error. So pretty much - a tiny syntax error can cause the error message and lead you down a road of debugging the wrong things. To solve this you have to find exactly where it is happening and narrow in your debuging.
execute this command with what is indicated a little above yarn test jest --env=node after this the error disappears
Make data pulled from a remote source available in NodeJS App
I'm just getting going with NodeJS and am trying to use jsforce (salesforce) to populate a dropdown on a form. I've written a module the requires jsforce, sets login params, and connects. ``modules/sftools.js const jsforce = require('jsforce') const conn = new jsforce.Connection({ loginUrl: process.env.SF_LOGINURL }) conn.login(process.env.SF_USER, process.env.SF_PASS) exports.metaDropDown = async (field) => conn.sobject...describe.. return arrayOfValues } I want to make the value returned available throughout my app, so in index.js I've got ``index.js const sftools= require('../modules/sftools') const roles = sftools.metaDropDown(process.env.SF_ROLES) and then I use some middleware to always set req.roles = roles. I think the problem is that I'm requesting the roles before the connection is established, but I can't figure out the flow. I tried logging in before the exports code, but I get an Invalid URL error, presumably because it isn't logged in yet. I tried to put the login code directly into the metaDropdown export, which got rid of the error, but there is still no data returned. Any suggestions?
I think the issue your having is that for the login function is expecting a callback as the third argument. conn.login(process.env.SF_USER, process.env.SF_PASS, function() { // do your role logic here. }) Hope this helps.
Pact-js: POST body is garbled by VerifyProvider
I'm running into an odd issue with Pact-js and POST bodies. The background: Consumer Side - I have a NodeJs app which I'm trying to test - I configured Pact and set up the appropriate framework - All test run successfully and generate contract Provider Side: - Again, I have a NodeJs app which I'm trying to test - Pact has been set up and framework in place - When i run the test, all GET requests run successfully, however all POSTs report a fail. The Issue: - When I echo out the POST body being passed to the service from Pact (veryifyProvider), i can see that its wrapped the body (JSON) inside another 'Key: value' pairing, where the body i want to parse is the Key and the value is empty. Its also added escape chars ( \ ) to all the double quotes inside the Body. EX: {"{\"Account\":\"123\",\"Orbit\":\"5.00\",\"Date\":\"2016-06-22\",\"Client\":\"1234\",\"Spring\":\"1234\"}":""} When i look in my Pact contract json, everything looks correct. Somewhere between VerifyProvider reading in the JSON and passing it to the REST endpoint, the body is mangled. This only seam to happen during tests, normal invocation works appropriately. Here is the code I'm using Provider side to execute the Verify: const verifier = require('pact').Verifier; const path = require('path'); let contract = path.join(__dirname, 'pactContract.json'); let opts = { providerBaseUrl: "http://localhost:3001", pactUrls: [contract], }; verifier.verifyProvider(opts) .then((res) => { console.log('pact veryify complete, !!!'); console.log(res); process.exit(0); }).catch((error) => { console.log(error); process.exit(1); }); I'm unable to pull down my exact consumer codebase, but its nearly identical in structure shown here Pact-js. Any help is VERY much appreciated!
Please check the Content-Type header and ensure it is application/json. This can happen if the service thinks it's matching text messages.
MongoDB won't save JSON document?
Quick question, but does anyone have a clue why MongoDB won't save the following document? I'm using MongoJS in NodeJS to connect to MongoDB and using the following lines of code to save (in my JS file, the function call is underneath the variable definition). The save function doesn't save, but automatically goes to the callback function. Any thoughts? Thanks so much :). Edit: After adding an error log to the callback, I'm getting the following error: { [MongoError: error parsing element 0 of field documents :: caused by :: wrong type for '0' field, expected object, found 0: "{"Word":"Count","read":1,"letter":1,"wh":1,"urging":2,"swift":1,"approval":1,"add'l":1,"lease":1,"space":1,"fayetteville":1,"vamc":1,"vets":2,"care":1..."] name: 'MongoError', ok: 0, errmsg: 'error parsing element 0 of field documents :: caused by :: wrong type for \'0\' field, expected object, found 0: "{"Word":"Count","read":1,"letter":1,"wh":1,"urging":2,"swift":1,"approval":1,"add\'l":1,"lease":1,"space":1,"fayetteville":1,"vamc":1,"vets":2,"care":1..."', code: 9 } db.collection.save(json_buffer, function() { console.log("Complete"); }); var json_buffer = {"Word":"Count","read":1,"letter":1,"wh":1,"urging":2,"swift":1,"approval":1,"add'l":1,"lease":1,"space":1,"fayetteville":1,"vamc":1,"vets":2,"care":1,"#gnip":3,"--":3,"delivering":3,"data":3,"happy":3,"customers":3,"outrageous":1,"france":1,"sell":1,"warships":1,"putin":1,"#senatorkirk":1,"#repkinzinger":1,"#usrepkeating":1,"&":5,"urge":1,"strong":1,"action":3,"polling":1,"shows":1,"race":1,"close":1,"pitch":1,"pre-primary":1,"deadline":1,"goal":2,"joining":1,"#teamcavuto":1,"shortly":1,"discuss":1,"can’t":1,"continue":1,"punt":1,"debt":2,"crisis":1,"road":1,"watch":1,"opening":1,"remarks":1,"today’s":1,"senate":1,"committee":1,"hearing":1,"mcdonald":1,"nomination":1,"urged":1,"passage":1,"#summermealsact":2,"yesterday":1,"#monticello":1,"#ny--so":1,"impt":1,"expand":1,"#usda's":1,"summer":2,"nutrition":1,"program":1,"great":2,"catch":1,"high":1,"school":2,"friend":1,"john":1,"choate":1,"today":7,"family":1,"capitol":1,"hill":1,"child":1,"america":1,"wake":1,"day":1,"wondering":1,"eat":1,"nebraska":1,"communities":1,"access":1,"local":1,"tv":1,"programming":1,"introduced":1,"bill":4,"work":2,"past":1,"time":2,"congress":1,"meaningful":1,"reduce":1,"threat":1,"cyber":1,"attacks":1,"#mercnews":1,"op-ed":1,"fitting":1,"#us_sfrc":1,"passed":1,"#crpd":1,"bob":1,"dole's":1,"bday":1,"#disabilitytreaty":1,"advocate":1,"beginning":1,"#isupportcrpd":1,"senator":1,"mcconnell":2,"co-sponsors":1,"protect":2,"correctional":1,"officers":2,"daily":1,"independent":2,"#ashland":1,"#kentucky":1,"millions":1,"children":2,"recv":1,"free":1,"reduced":1,"meals":1,"year":1,"left":1,"hungry":1,"months":1,"unacceptable":1,"rt":5,"#aterkel":1,"record":1,"phone":1,"#senschumer":1,"…":1,"good":1,"meeting":1,"anne":1,"rung":1,"nominee":1,"#ombpress":1,"office":2,"fed":1,"procurement":1,"policy":1,"cc":1,"#senatehsgac":1,"#federalreserve":1,"divert":1,"leftover":1,"funds":1,"foreclosure":1,"review":1,"hardest":1,"hit":1,"fund":1,"#ri":1,"supports":1,"corrections":1,"prisons":1,"manchester":1,"pine":1,"knot":1,"ashland":1,"inez":1,"lex":1,"miami":1,"valley":1,"well-run":1,"base":1,"makes":1,"wright-patt":1,"#1":1,"airmen":1,"#gopoversight":1,"release":1,"#irs":2,"needed":1,"days":1,"confirm":1,"lerner":1,"hard":2,"drive":1,"crash":2,"provide":1,"support":3,"runaway":1,"homeless":1,"youth":1,"victims":1,"trafficking":1,"#housefloor":1,"tomorrow":1,"glad":1,"signature":1,"industry":1,"#kydistillers":1,"#repandybarr":1,"obama":1,"meant":1,"flexibility":1,"re-elected":1,"thoughts":1,"prayers":1,"affected":1,"fires":1,"tooele":1,"pray":1,"staying":1,"safe":1,"#utpol":1,"hr":1,"passes":1,"house":1,"#repderekkilmer":1,"modernize":1,"labs":1,"fyi":1,"fun":1,"activities":1,"hosted":1,"google":1,"young":1,"inventors":1,"age":1,"13+":1,"choose":1,"projects":1,"virtual":1,"field":1,"trips":1,"joined":1,"nyc":1,"workforce":2,"development":2,"hosting":1,"roundtable":1,"#bronx":1,"failure":1,"disclose":1,"timely":1,"manner":1,"destroyed":1,"critical":1,"evidence":1,"reason":2,"special":1,"prosecutor":1,"26%":1,"texas":1,"live":1,"poverty":1,"#raisethewage":1,"#honorflightact":2,"codify":1,"process":1,"tsa":1,"expedited":1,"dignified":1,"screening":1,"veterans":1,"visiting":1,"war":1,"memorials":1,"humbled":1,"join":2,"medal":1,"honor":1,"recipient":1,"staff":1,"sergeant":1,"ryan":1,"pitts":1,"nashua":1,"ceremony":1,"pentagon":1,"icymi":1,"statement":1,"halbig":1,"burwell":1,"#ecpzachevans":1,"save":1,"date":1,"mt":1,"#shrinersfest":1,"dates":1,"announced":1,"shrinersfest":1,"june":1,"25-28":1,"feat":1,"#blueangels":1,"htt…":1,"unleash":1,"america's":1,"energy":2,"abundance":1,"create":1,"#jobs":1,"economic":1,"growth":1,"affordable":1,"#yes2energy":1,"marks":1,"#100days":1,"nigerian":1,"schoolgirls":1,"kidnapping":1,"forgotten":1,"#bringbackourgirls":1,"pleased":1,"mayor":1,"#rahmemanuel":1,"taking":1,"#fly2ohare":1,"noise":1,"measure":1,"seeks":1,"pay":1,"gratitude":1,"group":1,"americans":1,"make":1,"ultimate":1,"sacrifice":1,"stopped":1,"dutch":1,"embassy":1,"offer":1,"condolences":1,"lost":1,"loved":1,"#mh17":1,"#obamafailures":1,"min":1,"#131":1,"odds":1,"drives":1,"irs":1,"claims":1,"win":1,"fl":1,"lottery":1,"times":1,"#tcot":1}
Struggled with this for a long time, despite reading up here. Actual cause of the issue finally turned out to be that the JSON object I was trying to update was 'undefined'. Try catching the mongo error and printing the entire error object. The JSON object was being considered as undefined in my case because it was actually an array, not an object. So I tried doing a mongo update on myJsonObject[0] rather than myJsonObject which was actually an array, and this succeeded. Do a console.log of the stringified json 'object' you are trying to save, and if it's surrounded by square braces, then you know you're dealing with an array, and need to work on its element(s) instead.
I had this error when: Create JSON object in client code Send it over http request Get it from the request body in node code Send the body content to mongodb The problem was the object sent was a String, not a JSON object... Using var json = JSON.parse(json-string-from-body) and send json solve my problem. Also, I used insert() method not save(). In mongodb console save({"htt…":1}) which is a part of your data return an error but insert({"htt…":1}) works fine.
I got this error with Mongoose when doing Model.update(docId, {...}) when I should have been doing Model.update({_id: docId}, {...})