Protractor Test with oracle Db - javascript

I requirement to test the DB alongside my angular app. The scenario is such that I do something on UI and see if the value persists in the DB(Oracle)
For this purpose, I installed node oracle DB package and was able to run a simple SELECT statement using the command "Node filename.js". The config and the select statement were present in the filename.js
Next, I tried to include the same steps in my step definition. The first step of my test case navigates to the application home page and the next step is to run a simple select statement. I have no asserts as I wanted to first get a basic query working
Here is my step def
let oracledb = require('oracledb');
let dbConfig = require('../configs/dbConfig');
Given(/^I run a random select query$/, function() {
let sql2 = "Select * from tablename Where columname = 8888901";
oracledb.getConnection(dbConfig).then(function(connection) {
//return console.log('Connected to database');
return connection.execute(sql2).then(function(result, err) {
return console.log(result.rows.toString());
});
});
});
When the test runs the browser opens and the home page is loaded and then the test is passed. I don't think the 2nd step is even run as the query result is not printed in the console.
Could someone please point me in the right direction. Can protractor work with OracleDB? have I written the test correct? I have so many questions regarding this and there is not a single online sample for a protractor test with oracledb. Any inputs here will be helpful, thanks

Related

Knex.js migration issue: Fails with ` relation "knex_migrations" does not exist`

I've been using knex.js successfully for a while now on this project, first time I've come accross this. I deleted all my migration files and dropped my db (locally) and instead used pg_dump to get the DDL and all data from my prod database (not including knex_migrations or knex_migrations_lock tables).
I created a new migration script and used knex.raw to paste all the SQL in. When I ran the migration script, I get the following:
error: insert into "knex_migrations" ("batch", "migration_time", "name") values ($1, $2, $3) - relation "knex_migrations" does not exist
This migration script is being run on a brand new database. When I change what's in the script to just be basic DDL, it works fine. So something about the result of pg_dump and trying to run it using knex is causing it to bomb out.
This isn't a ton of data either really, so I'm not too sure where I'm going wrong - knex is responsible for creating the migration tables and I've made sure there's no mention of knex or migration tables in the DDL.
Any suggestions would be greatly appreciated :)
The table knex_migrations and knex_migrations_lock will be created on running the command
knex migrate:make <name of migration>
Could you please confirm you have executed above knex command.
Once that is done running
knex migrate:latest
should create all schema you have mention. knex.raw
Using pd_dump to dump a database to an sql file, there occurs some additional lines in the beginning of the sql such as:
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
comment those out and the migration should work. You can uncomment one statement at a time to see which one is causing the problem.
I just went down this hole. The following line is the culprit.
SELECT pg_catalog.set_config('search_path', '', false);
It's removing your search path so knex doesn't know where to find anything.

Node.js - Serverside Command Promp Commands input?

I´m writing a Web MMO with Node.js and for debug and maintenance reasons i would love to have the ability to open my SSH connection, where i also start my server, and write a command like "logout all".
So what are my options to get command prompt input and use it while my server runs?
Example:
I start my server with "node app.js" - server starts.
Now i want to write something into the command prompt - how do i get said input so i can use it in my code?
I was trying to read into node.js-readline but i cant seem to find much about it and everything that i found about it needs a "question" to be asked so it can get the input.
I would love to have something like this:
var command = getCommandlineInput(); //command = "logout all"
It need to get any input any time. A callback function would be good aswell, so i can direktly run it throu a checkCommand() function.
So i just figured out how to do this:
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.on('line', (input) => {
useCommand(input);
});
function useCommand (input)
{
switch (input) {
case "show userlist":
CMD_showUserlist();
break;
}
}
First we initiate readline.
With readline.on we listen for any input you type into the command prompt.
useCommand() takes this input and chose what function to run.
How to work with the given input string is up to you, in my example i just made a hard coded command "show userlist".

Giveaway commands does not save (Heroku) discord.js

I am making a giveaway command, but whenever I restart all dynos in heroku it seems the giveaway just froze(Never ends the giveaway) and when I do !gdelete {messageid} It says there is no giveaway for {messageid} any idea why and how to fix it. I have tried using quick.db but still the same and I am quite new to heroku and coding discord bot. Im using node.js
const { GiveawaysManager } = require("discord-giveaways");
const manager = new GiveawaysManager(bot, {
storage: "./giveaways.json",
updateCountdownEvery: 10000,
default: {
botsCanWin: false,
embedColor: "#FF0000",
reaction: "🎉"
}
})
bot.giveawaysManager = manager;
Heres the code
And heres the gstart command: https://pastebin.com/9tBjpVEY
The issue is caused by Heroku, which doesn't store local files when you're not running the app. Every time you restart a dyno Heroku deletes everything and rebuilds it: that means that if you save your files locally when it restarts they'll get deleted.
To solve this issue you need either to switch to another service or to create some form of backup for your file.
You could also use a remote database, but I don't know how that could be implemented with the discord-giveaways package.
I had the same issue and I think that it can be solved by doing this:
Instead of using quick.db, you can use quickmongo which just the same as quick.db and discord-giveaways also has an example of it. Although there is one change that you need to make. The example of quickmongo also shows a local way to store the files but instead of typing the localhost string, replace it with the MongoDB Compass connection string of your MongoDB cluster and give the new collection the same name which is giveaways.
In order to get the connection string, log in to your MongoDB account and create a cluster. After creating the cluster, click the connect button on the cluster and then select Connect using MongoDB Compass. From there you will see a connection string. Copy and paste that string in the place where there was the localhost string. Then replace <password> with your account's password which is your password with your username. Also, replace the test at the end with giveaways and you are good to go. After running the code, you would also see a collection named giveaways in the Collections Tab inside your cluster.
Example:
const db = new Database('connectionLink/giveaways');
db.once('ready', async () => {
if ((await db.get('giveaways')) === null) await db.set('giveaways', []);
console.log('Giveaway Database Loaded');
});

Searching pages in Electron?

I’m currently working on designing a program in Electron. One of the key parts to this program will be a search option. Similar to other websites that you can search the whole site for pages that match your inquiry, I would like to search within the “pages”/“html files” of my program and have it display the search results. Preferably a letter at a time display in real time so one can see results as they type, but even an option with search will do. I just need to search within my program pages, not an external site. I’m having trouble figuring out how to get started implementing this, since PHP isn’t supported in Electron. I know react can do the letter at a time real time searching, but I’m not sure how to do the search of other pages or how to parse them for searching. Any suggestions, guidelines, or frameworks to get me on the right track would be helpful. Thanks!
EDIT: I’m also aware of the webcontents.findInPage() function, but that only searches the current page, not other pages in the project path. I am fine defining which pages to search manually if I can find a way to actually search them.
If you store all your pages in a directory like "views" you can use fs to read each file and search its content.
I have made a quick example of something you could make to do this:
// The directory containing all your pages
let directoryToYourPagesOrHTMLFiles = "/your/directory/";
// Require fs so you can get all the files and file content
const fs = require("fs");
// Require html-to-text so you can parse the HTML in the files
// into text so you can search on the data easier
let htmlToText = require('html-to-text'); // npm install --save html-to-text
// Run this function when a user enters a character
function userTyped(inputValue) {
// Foreach file in the directory
fs.readdir(directoryToYourPagesOrHTMLFiles).forEach(filename => {
// Read the file contents
fs.readFile(directoryToYourPagesOrHTMLFiles + "/" + filename, "utf8", (err, data) => {
// If there was an error reading the file log it
if(err) {
console.log(err);
} else {
// If there was no error, parse the HTML into text
let text = htmlToText.fromString(data);
// Perform your search on the next using the inputValue
// Example Search:
if(text.indexOf(inputValue) > -1) {
// Display the page in your search results
displaySearchResult(directoryToYourPagesOrHTMLFiles + "/" + filename);
}
}
});
});
}
function displaySearchResult(pagePath) {
/*
Add the page to a results page
*/
}
I didn't test this because it did it in a rush but it shows the concept of what you need to do!
Hope this helps you!

Finding saved data from mongo shell (no output)

Here is the code for initialization
mongoose.connect('mongodb://localhost/gpsdb');
var db = mongoose.connection;
db.on('open', function () {
// now we can start talking
});
After successful opening, I am saving data like this, it's giving me no errors.
function saveGPSData(data){
var newData = new GPSData(data);
newData.save(function(err){
if(err)
return console.error(err);
});
}
Now in mongo shell, I am trying to retrieve that data but it's giving me empty output.
> use gpsdb
> db.GPSData.find();
>
It's giving me no output. Also can I found what models are there in gpsdb?
Here is the full source code http://pastebin.com/K7QPYAx8
JUST FOUND THAT in db folder there these files for my db created by mongodb
/data/db/gpsdb.0
/data/db/gpsdb.1
/data/db/gpsdb.n
A good place to start to get a quick answer is
https://groups.google.com/forum/#!forum/mongoose-orm
the community is very responsive :)
In the shell I did the following
>use gpsdb
switched to gpsdb
>db show collections
gpsdatas
From here I found that collection name is gpsdatas...... Not sure why its adding extra (s) to my modal, although you can see from the code that I am setting Modal to
var GPSData = mongoose.model('GPSData', GPSDataSchema);
Now using the shell its working like this
>db.gpsdatas.find()

Categories