Jest failing tests on same objects - unit-testing

One of my unit tests fail with output like the below
expect(jest.fn()).toHaveBeenCalledWith(...expected)
- Expected
+ Received
- {"cartId": "_id_", "devices": [{"foo": "bar"}], "language": "_language_", "province": "_province_"},
+ {"cartId": "_id_", "devices": [{"foo": "bar"}], "language": "_language_", "province": "_province_"},
for line
expect(mockTransformer).toHaveBeenCalledWith({...
The question is, if expected and received are same, how can this tests fail?
Here is the test code in picture:
expect(mytestingfunction).toHaveBeenCalledWith({
devices: [{ foo: 'bar' }],
cartId: '_id_',
language: '_language_',
province: '_province_'
})

Related

Updating location data into the server is not working using background geo locaion in ionic 3

I am using https://github.com/mauron85/cordova-plugin-background-geolocation. It gives location details in the foreground and gives debug messages when the app is closed but it does not update the location details into the server both foreground and background.
Thanks in advance
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 10,
distanceFilter: 10,
debug: false,
stopOnTerminate: false,
startForeground: true,
notificationTitle: 'location tracking',
notificationText: 'Active',
interval: 60000,
url: localStorage.getItem('api_base_url')+'user/currentlocation',
syncUrl:localStorage.getItem('api_base_url')+'user/currentlocation',
httpHeaders: {
'Content-Type': 'application/json'
},
postTemplate: {
lat: '#latitude',
lon: '#longitude',
user_id: '1',
currentDate: '12-12-2019',
address: 'test',
}
};
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
});
});
this.backgroundGeolocation.start();
Background geo location post template
Keep in mind that all locations (even a single one) will be sent as an array of object(s), when postTemplate is jsonObject and array of array(s) for jsonArray!
In server-side, I changed the JSON object to an array of object.
For example,
{
"user_id": "1",
"lon": "13.2",
"lat": "82.3"
}
I changed the above JSON object to following
[{
"user_id": "1",
"lon": "13.2",
"lat": "82.3"
}]

How to fix error import Vue from 'vue' results in SyntaxError: Unexpected identifier

I'm trying to setup a test framework for a Vue.js project that I'm working on. I'm trying to use Jest for this but I end up with an error I don't seem to find a solution for. When I'm trying to run the tests, I get a syntax error in the terminal.
The error I'm getting is:
Test suite failed to run
Import Vue from 'vue';
^^^
SyntaxError: Unexpected identifier"
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
I've been looking around but I can't find a solution that helps me..
When removing the import of Vue, the test passes.
I run the tests by command npm run tests
// package.json
{
"name": "mlink-pwa",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"tests": "NODE_ENV=testing vue-cli-service test:unit"
},
"dependencies": {
"chart.js": "^2.7.3",
"chartjs-plugin-labels": "^1.1.0",
"countup.js": "^1.9.3",
"dexie": "^2.0.4",
"gauge-chart": "^0.4.3",
"moment": "^2.22.2",
"progressbar.js": "^1.0.1",
"raven-js": "^3.27.0",
"register-service-worker": "^1.5.2",
"vue": "^2.5.17",
"vue-countup-v2": "^2.0.0",
"vue-i18n": "^8.3.2",
"vue-router": "^3.0.2",
"vuedraggable": "^2.16.0",
"vuelidate": "^0.7.4",
"vuex": "^3.0.1"
},
"devDependencies": {
"#babel/preset-env": "^7.3.1",
"#vue/cli": "^3.1.3",
"#vue/cli-plugin-babel": "^3.1.1",
"#vue/cli-plugin-e2e-nightwatch": "^3.4.0",
"#vue/cli-plugin-eslint": "^3.1.5",
"#vue/cli-plugin-pwa": "^3.1.2",
"#vue/cli-plugin-unit-jest": "^3.4.0",
"#vue/cli-service": "^3.1.4",
"#vue/eslint-config-standard": "^4.0.0",
"#vue/test-utils": "^1.0.0-beta.25",
"babel": "^6.23.0",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"eslint-plugin-jasmine": "^2.10.1",
"jasmine": "^3.3.1",
"node-sass": "^4.10.0",
"sass-loader": "^7.1.0",
"vue-jest": "^3.0.2",
"vue-template-compiler": "^2.5.17"
}
}
// jest.config.js
module.exports = {
moduleFileExtensions: ['js', 'json', 'vue'],
transform: {
'^.+\\.jsx?$': 'babel-jest',
'^.+\\.vue$': 'vue-jest'
},
clearMocks: true,
coverageDirectory: "coverage",
};
// babel.config.js
module.exports = {
env: {
testing: {
presets: [
['env', { modules: false }],
'#babel/preset-env',
'#vue/app'
],
plugins: [
'transform-es2015-modules-commonjs'
]
}
}
}
// first.spec.js - THIS FAILS
import Vue from 'vue'
describe('', () => {
it('first test', () => {
expect(true).toEqual(true);
});
});
// first.spec.js - THIS PASSES
describe('', () => {
it('first test', () => {
expect(true).toEqual(true);
});
});
Expected:
I expect the test suite to run and the test to pass.
Actual:
The test suite does not run.
This is a problem with a particular version of vue-cli. Installing the latest and starting a new project resolves the issue. Or alternately do this in a "mock" project and copy all the npm dependency versions over to your existing project.

DynamoDB Update item wothout any action. Full rewrite

I need to rewrite almost all in complex item schema.
I can't find the way to rewrite it without actions.
I've found the only way to send old and new item attributes, delete all by using old attrs and then add all from new one.
And make it by Class: Aws::DynamoDB::Types::UpdateItemInput
http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Types/UpdateItemInput.html
Does it have another method?
Scheme is like:
{
"app_params": {
"production_params": {
"hard_time_control": true,
"index_max": 300,
"time_control": true,
"weight_fix": 100,
"weight_max": 200
},
"search_mx": "11g"
},
"client": "client_name",
"dashboard": false,
"data": true,
"test_port": 123,
"servers": [
{
"name": "server1",
"port": 123,
"search_type": "test"
}
],
"stock_port": 456
}
Thanks to jarmod.
The decision is PutItem method
http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#put_item-instance_method

Pretender and QUnit: Error: Assertion Failed: The response from a findQuery must be an Array, not undefined

A recent update seems to have broken my tests. I'm using Pretender to mock server calls, and I'm getting the error Error: Assertion Failed: The response from a findQuery must be an Array, not undefined.
Note that I don't get errors when I visit that page in my app. This error only appears when I run the test.
I've already looked at this, this, and this, but none of those solutions seem to apply in my case.
Here's the relevant code in my Pretender helper:
var scores = [
{
id: 1,
name: 'score 1'
}
];
var levels = [
{
id: 1,
name: 'level 1',
score_id: 1
}, {
id: 2,
name: 'level 2',
score_id: 1
}, {
id: 3,
name: 'level 3',
score_id: 1
}
];
return new Pretender(function() {
this.get('api/v1/scores/:id', function(request) {
var score = scores.find(function(score) {
// in the failing test, request.params.id is '1'
if (score.id === parseInt(request.params.id, 10)) {
return score;
}
});
return [200, {"Content-Type": "application/json"}, JSON.stringify({
score: score,
levels: levels
})];
});
});
And this is the test:
test('displays "Project Score"', function() {
visit('/projects/32/scores/1');
andThen(function() {
equal(find('h3.title').text(), 'Project Score');
});
});
Note that this only affects tests using dynamic routes like the one above. Tests that use this route work normally:
this.get('api/v1/scores', function(request) {
return [200, {"Content-Type": "application/json"}, JSON.stringify({
scores: scores
})];
});
I tried bypassing the find by doing this:
this.get('api/v1/scores/:id', function(request) {
return [200, {"Content-Type": "application/json"}, JSON.stringify({
score: [
{
id: 1,
name: 'score 1'
}
],
levels: levels
})];
});
However, I still get the same error.
Any ideas? How would I debug this issue?
Assorted versions:
Ember CLI: 0.1.12
Node: 0.10.33
NPM: 2.1.8
Ember: 1.10.0
Ember Data: 1.0.0-beta.15
Ember CLI Pretender: 0.3.1
Pretender: 0.6.0
Handlebars: 2.0.0
HTMLBars: ^0.7.4
Ember QUnit: 0.1.8
Ember QUnit Notifications: 0.0.6
QUnit: 1.17.1

EmberJS auto loading inverse relations?

I have a model like:
var Survey = DS.Model.extend({
title: DS.attr('string'),
});
and:
var SurveySection = DS.Model.extend({
survey: DS.belongsTo('survey', {async:true}),
title: DS.attr('string'),
help_text: DS.attr('string'),
});
If i have a survey object, can I just do survey.get('survey_section') to get all the sections associated with a particular survey, because this isn't working? It doesn't even work if I add a survey_sections: DS.hasMany('survey_sections', {async:true}) to my survey model.
I should add that I'm using fixtures. When I release the app they'll still be used (ie so if the RESTAdapater would fix it, that's not a fix in my case):
Survey.reopenClass({
FIXTURES: [
{
"id": 1,
"title": "Favourite food"
},
{
"id": 2,
"title": "Sports"
}
]
});
and:
SurveySection.reopenClass({
FIXTURES: [
{
"help_text": "",
"id": 1,
"survey": 1,
"title": "Italian food"
},
{
"help_text": "",
"id": 2,
"survey": 1,
"title": "Team sports"
}, ...]});
Is the fixture adapter not able to retrieve related records in the reverse direction like this? If not, will I have to go the laborious route of manually getting the sections with survey=1, for example (laborious because I'll have to take this approach throughout my whole app with other models)?
Update
Specifically my failing code is (with survey 1):
this.get('survey').get('survey_sections').then(function(survey_sections) {
// survey_sections contains no objects, so objectAt(0) returns undefined.
survey_sections.objectAt(0).get('questions').then(function(questions) {
console.log('Set first question ID to ' + self.get('firstQuestionId'));
});
});
As the fixtures show there should be 2 SurveySection objects in survey_sections, but instead none are found.
I didn't want to do it, but I had to add the forward relation to the items in the Survey fixture, e.g.:
Survey.reopenClass({
FIXTURES: [
{
"id": 1,
"title": "Favourite food",
"survey_sections": [1, 2],
},
{
"id": 2,
"title": "Sports",
"survey_sections": [3],
}
]
});
and update the Survey model with:
survey_sections: DS.hasMany('survey_sections', {async:true})