Skip to content

Commit

Permalink
Merge pull request reactioncommerce#2019 from reactioncommerce/brent-…
Browse files Browse the repository at this point in the history
…fix-issue-1837

Remove unnecessary call to `shop/getLocale`, eliminate unused code
  • Loading branch information
Aaron Judd authored Mar 28, 2017
2 parents 986d403 + 66a3137 commit a1a0cf5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 86 deletions.
29 changes: 0 additions & 29 deletions client/modules/core/helpers/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,6 @@ export function toggleSession(sessionVariable, positiveState) {
return Session.get(sessionVariable);
}

/**
* locateUser
* @return {Object} set and return session address based on browser latitude, longitude
*/
export function locateUser() {
function successFunction(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
return Meteor.call("shop/locateAddress", lat, lng, function (error,
address) {
if (address) {
return Session.set("address", address);
}
});
}

function errorFunction() {
return Meteor.call("shop/locateAddress", function (error, address) {
if (address) {
return Session.set("address", address);
}
});
}

if (navigator.geolocation) {
return navigator.geolocation.getCurrentPosition(successFunction,
errorFunction);
}
}

/**
* getCardTypes
Expand Down
11 changes: 11 additions & 0 deletions server/api/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ export default {
return shop && shop.currency || "USD";
},

getShopLanguage() {
const { language } = Shops.findOne({
_id: this.getShopId()
}, {
fields: {
language: 1
} }
);
return language;
},

getPackageSettings(name) {
return Packages.findOne({ packageName: name, shopId: this.getShopId() }) || null;
},
Expand Down
22 changes: 3 additions & 19 deletions server/api/core/email/email.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from "meteor/meteor";
import { Job } from "meteor/vsivsi:job-collection";
import { Jobs, Templates } from "/lib/collections";
import { Logger } from "/server/api";
import { Reaction, Logger } from "/server/api";


/**
Expand Down Expand Up @@ -33,14 +33,7 @@ export function getSubject(template) {
}

// set default
let language = "en";

const shopLocale = Meteor.call("shop/getLocale");

// set the language if found
if (shopLocale && shopLocale.locale && shopLocale.locale.languages) {
language = shopLocale.locale.languages;
}
const language = Reaction.getShopLanguage();

// check database for a matching template
const tmpl = Templates.findOne({
Expand All @@ -52,8 +45,6 @@ export function getSubject(template) {
if (tmpl && tmpl.template) {
return tmpl.subject;
}

// otherwise, use the default template from the filesystem
return "A message from {{shop.name}}";
}

Expand All @@ -71,14 +62,7 @@ export function getTemplate(template) {
}

// set default
let language = "en";

const shopLocale = Meteor.call("shop/getLocale");

// set the language if found
if (shopLocale && shopLocale.locale && shopLocale.locale.languages) {
language = shopLocale.locale.languages;
}
const language = Reaction.getShopLanguage();

// check database for a matching template
const tmpl = Templates.findOne({
Expand Down
38 changes: 0 additions & 38 deletions server/methods/core/methods.app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,42 +116,4 @@ describe("Server/Core", function () {
return done();
});
});

describe.skip("shop/locateAddress", function () {
it("should locate an address based on known US coordinates", function (done) {
this.timeout(20000);
const address = Meteor.call("shop/locateAddress", 34.043125, -118.267118);
expect(address.zipcode).to.equal("90015");
return done();
});

it("should locate an address with known international coordinates", function () {
this.timeout(20000);
const address = Meteor.call("shop/locateAddress", 53.414619, -2.947065);
expect(address.formattedAddress).to.not.be.undefined;
expect(address.formattedAddress).to.contain("248 Molyneux Rd, Kensington");
expect(address.formattedAddress).to.contain("Liverpool");
expect(address.formattedAddress).to.contain("L6 6AW");
expect(address.formattedAddress).to.contain("UK");
});

it("should provide default empty address", function (done) {
this.timeout(20000);
const address = Meteor.call("shop/locateAddress", 26.352498, -89.25293);
const defaultAddress = {
latitude: null,
longitude: null,
country: "United States",
city: null,
state: null,
stateCode: null,
zipcode: null,
streetName: null,
streetNumber: null,
countryCode: "US"
};
expect(_.isEqual(address, defaultAddress)).to.be.true;
return done();
});
});
});

0 comments on commit a1a0cf5

Please sign in to comment.