So, Am writing a Qunit test (with teaspoon as the test runner), for an Ember application that uses ember-simple-auth gem for login authintication, My test is as follows (coffee script) :
#= require qunit_spec_helper
test "Employee signs in", ->
expect(1)
visit("/login").then(->
fillIn "input.email", "employee1#example.com"
).then(->
fillIn "input.user_password", "password1"
).then(->
click "button.btn-primary"
).andThen ->
equal(find('h2').length,1, "Welcome to the App")
And here is the Test helper:
QUnit.testStart ->
Ember.run ->
App.reset()
Ember.testing = true
App.setupForTesting()
App.injectTestHelpers()
QUnit.testDone ->
Ember.testing = false
QUnit.done ->
Ember.run ->
App.reset()
When I run the test (keeping any eye on the console), I get the following error:
POST http://localhost:3000/teaspoon/qunit/oauth/token 404 (Not Found)
I can't seem to be able to login, No matter what ..
I ran out of ideas, Any help/Advice is highly Appreciated :)
Ember.SimpleAuth makes a request against the server to authenticate the session when the button is clicked - the route isn't handled by your server though (or the server isn't running at all maybe?) I'd stub the token endpoint for testing, find an example e.g. here: https://github.com/digitalplaywright/eak-simple-auth/blob/master/tests/acceptance/login-test.js
Related
On the frontend of my application I use the #microsoft/signalr library to send off requests to my backend hubs. This works okay in a single tab, but when a second tab is open an error is outputted to the console of the first tab and the connection stops. It's almost as if the second tab is taking over for some reason, when really I believe both should be connected to the hub on different connections with different connection ids. The error I receive in the console is as follows:
[2021-04-23T09:34:22.762Z] Information: WebSocket connected to wss://localhost:6001/ptwHub?id=39HKWle3NU0eTjFxcNWsiQ.
Utils.js:218 [2021-04-23T09:34:32.895Z] Error: Connection disconnected with error 'Error: Message is incomplete.'.
./node_modules/#microsoft/signalr/dist/esm/Utils.js.ConsoleLogger.log # Utils.js:218
./node_modules/#microsoft/signalr/dist/esm/HttpConnection.js.HttpConnection.stopConnection # HttpConnection.js:542
transport.onclose # HttpConnection.js:479
./node_modules/#microsoft/signalr/dist/esm/WebSocketTransport.js.WebSocketTransport.close # WebSocketTransport.js:189
webSocket.onmessage # WebSocketTransport.js:129
ptw.ts:22 Error: Message is incomplete.
at Function../node_modules/#microsoft/signalr/dist/esm/TextMessageFormat.js.TextMessageFormat.parse (TextMessageFormat.js:13)
at JsonHubProtocol../node_modules/#microsoft/signalr/dist/esm/JsonHubProtocol.js.JsonHubProtocol.parseMessages (JsonHubProtocol.js:36)
at HubConnection../node_modules/#microsoft/signalr/dist/esm/HubConnection.js.HubConnection.processIncomingData (HubConnection.js:507)
at WebSocketTransport.HubConnection.connection.onreceive (HubConnection.js:73)
at WebSocket.webSocket.onmessage (WebSocketTransport.js:126)
The code to connect to the hub is as follows:
let connection = new signalR.HubConnectionBuilder().withUrl("https://localhost:6001/hub").build();
connection.on('knowledgeBaseUpdated', (userId: number) => {
alert(`User ${userId} has updated the knowledge base. Please refresh.`);
});
connection.start().catch(err => console.log(err));
Really not sure why the second tab would just take over the connection instead of creating a new connection. There is obviously an issue here somewhere but I'm really not sure where so any help would be really appreciated.
EDIT
I've enabled client side debugging for signalr and get the following output. The line which starts with HttpConnection.stopConnection is the line which appears when a new connections is attempted from a different tab.
[2021-04-26T09:50:00.084Z] Debug: Starting HubConnection.
Utils.js:228 [2021-04-26T09:50:00.096Z] Debug: Starting connection with transfer format 'Text'.
Utils.js:228 [2021-04-26T09:50:00.099Z] Debug: Sending negotiation request: https://localhost:6001/ptwHub/negotiate?negotiateVersion=1.
Utils.js:228 [2021-04-26T09:50:00.365Z] Debug: Selecting transport 'WebSockets'.
Utils.js:224 [2021-04-26T09:50:00.667Z] Information: WebSocket connected to wss://localhost:6001/ptwHub?id=14d1O9-cj544_-SHeZ2fgw.
Utils.js:228 [2021-04-26T09:50:00.667Z] Debug: The HttpConnection connected successfully.
Utils.js:228 [2021-04-26T09:50:00.668Z] Debug: Sending handshake request.
Utils.js:224 [2021-04-26T09:50:00.669Z] Information: Using HubProtocol 'json'.
Utils.js:228 [2021-04-26T09:50:13.079Z] Debug: Server handshake complete.
Utils.js:228 [2021-04-26T09:50:13.081Z] Debug: HttpConnection.stopConnection(Error: Message is incomplete.) called while in state Connected.
Utils.js:218 [2021-04-26T09:50:13.081Z] Error: Connection disconnected with error 'Error: Message is incomplete.'.
./node_modules/#microsoft/signalr/dist/esm/Utils.js.ConsoleLogger.log # Utils.js:218
./node_modules/#microsoft/signalr/dist/esm/HttpConnection.js.HttpConnection.stopConnection # HttpConnection.js:542
transport.onclose # HttpConnection.js:479
./node_modules/#microsoft/signalr/dist/esm/WebSocketTransport.js.WebSocketTransport.close # WebSocketTransport.js:189
webSocket.onmessage # WebSocketTransport.js:129
Utils.js:228 [2021-04-26T09:50:13.082Z] Debug: HubConnection.connectionClosed(Error: Message is incomplete.) called while in state Connecting.
Utils.js:228 [2021-04-26T09:50:13.083Z] Debug: Hub handshake failed with error 'Error: Message is incomplete.' during start(). Stopping HubConnection.
Utils.js:228 [2021-04-26T09:50:13.083Z] Debug: Call to HttpConnection.stop(Error: Message is incomplete.) ignored because the connection is already in the disconnected state.
Utils.js:228 [2021-04-26T09:50:13.084Z] Debug: HubConnection failed to start successfully because of error 'Error: Message is incomplete.'.
When the connection starts on a particular tab, I can see the connection has started and I get a single message when I look at the Network tab of Chrome Dev Tools. When I open the second tab, another message is sent to the first time which looks like an error message.. it weirdly contains a load of red dot characters? I
mage attached below. Please ignore the fact it's called ptwHub as I removed the ptw part previously to make it easier for the readers to understand.
I am building a web app that allows users to type in phone numbers and send text messages via the Twilio API. I've built the functionality in a file, shown below. If I cd to this file and run node twilioActions.js, the text message gets sent.
var client = require('twilio')(CLIENT_ID, CLIENT_SECRET);
// ideally, I'd like to send the message using this method and call this from other JavaScript files
export const sendMessage = () => {
}
// the following code works when I run 'node twilioActions.js'
client.sendMessage({
to:'...',
from: '...',
body: 'Text message test.'
}, function(err, responseData) {
if (!err) {
console.log(responseData.from); // outputs "+14506667788"
console.log(responseData.body); // outputs "word to your mother."
}
});
However, I want to call the sendMessage method from a different React file. Here is it:
import * as twilioActions from './twilioActions';
class PhoneView extends React.Component{
// other methods are hidden obviously, the one below is called when a button is pressed to send a message.
sendMessage() {
twilioActions.sendMessage();
}
}
When I try to build the project, I get the following errors:
ERROR in ./~/twilio/package.json
Module parse failed:/Users/Felix/Desktop/ECE590/node_modules/twilio/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "twilio",
# ./~/twilio/lib/Client.js 5:17-43
ERROR in ./~/request/lib/har.js
Module not found: Error: Cannot resolve module 'fs' in /Users/Felix/Desktop/ECE590/node_modules/request/lib
# ./~/request/lib/har.js 3:9-22
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
# ./~/tunnel-agent/index.js 3:10-24
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
# ./~/tunnel-agent/index.js 4:10-24
I feel like I am making a simple mistake and perhaps am not using the correct libraries or including the proper references. Could someone point me in the right direction about how to get this to work? Thank you so much!
Twilio developer evangelist here.
The twilio npm module is not built or recommended for use in the front end. The main thing is that you would need to expose your account credentials in the front end code of your site. This is a security risk as it means a malicious attacker could get hold of your credentials and abuse your Twilio account.
I recommend creating a service on your server side that you can call to with an AJAX request in order to perform actions like this.
I have a very simple test case of API done with usage of loopback-testing module.
lt = require('loopback-testing')
assert = require('assert')
describe '/profile', ->
lt.beforeEach.withApp app
lt.describe.whenCalledRemotely 'GET', '/api/profiles/ping', { data: 'test' }, ->
lt.it.shouldBeAllowed()
it 'should have statusCode 200', ->
assert.equal #res.statusCode, 200
it 'should have pong response', ->
assert.equal #res.body.pong, 'test'
and as result of testing I'm getting printed lines at the system console like this ones:
/profile
GET /api/profiles/ping
GET /api/profiles/ping 200 50.639 ms - 15
✓ should be allowed
GET /api/profiles/ping 200 8.026 ms - 15
✓ should have statusCode 200
GET /api/profiles/ping 200 3.633 ms - 15
✓ should have pong response
Is there a way to turn off writing these lines to system console by loopback-testing module? It's simply trashes my mocha reports overview.
Do you have any logging middleware configured in your application? The extra lines look like HTTP access logs produced by morgan.
You need to disable any HTTP logging middleware in your application when running the tests. The instructions for that depend on how you have configured this middleware, could you please extend your question and describe your app setup?
I writing an app in Angular + Flask hosted on heroku. I've been looking to use html5mode to use myapp.co/register for oauth. The problem with html5mode is that server needs to rewrite url if someone refreshes the page or clicks the link that is not root. I tried to use this snippet to catch them all, but it doesn't work.
#app.route("/", defaults={"path": ""})
#app.route("/<path:path>")
def index(path):
print path
return make_response(open(app.static_folder + "index.html").read())
output 404
* Restarting with reloader
127.0.0.1 - - [23/Jan/2014 13:41:48] "GET /ass HTTP/1.1" 404 -
App got root that servers index.html and /api/v1/ that is RESTful api
You need to use something more than you have:
#app.route("/", defaults={"path": ""})
#app.route("/<string:path>") <--- this is missing
#app.route("/<path:path>")
def index(path):
print path
return make_response(open(app.static_folder + "index.html").read())
So:
#app.route("/<string:path>")
is missing. It catches string variables (not path), so in your case just ass from your example, when you try to hit http://localhost:5000/ass.
Your code will catch all urls if you do not have any more routes with more highest priority. But look like it should return 500 error (because I hope you do not have <app_path>/staticindex.html and use unsafe method to send file).
So if you have another rules you must look at rule priority (see https://stackoverflow.com/a/17146563/880326).
If you have error with this route better use:
#app.route("/", defaults={"path": ""})
#app.route("/<path:path>")
def index(path)
return send_from_directory(app.static_folder, "index.html")
I followed the docs on the websocket-rails github wiki page, but couldn't overcome this difficulty, I get this error with chrome:
WebSocket connection to 'ws://0.0.0.0:3000/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301
I installed the websocket-rails gem, generated the install, I set successfully config.middleware.delete Rack::Lock in development.rb; I'm using Rails 4.
I got in the view:
<script type="text/javascript">
var dispatcher = new WebSocketRails('0.0.0.0:3000/websocket');
</script>
I got in my chat_controller.rb:
class ChatController < WebsocketRails::BaseController
def initialize_session
puts "Session Initialized"
end
def user_connected
puts 'user connected'
end
end
in my events.rb:
WebsocketRails::EventMap.describe do
subscribe :client_connected, :to => ChatController, :with_method => :user_connected
end
As you can see, my goal is to display "Session Initialized", and "user connected", in my thin server console each time that someone goes on a page. Between, I run the server with bundle exec thin start, but I got a javascript error instead (websocket connection failed error 301).
Thanks to the members of the Websocket Rails IRC, I found out that in my route, I was appending the locale before every path, so it coudln't find it.
Check your routes.rb if someone hit that issue too !