diff --git a/src/astrologer/houses.js b/src/astrologer/houses.js index 8361b3b..c299478 100644 --- a/src/astrologer/houses.js +++ b/src/astrologer/houses.js @@ -6,38 +6,37 @@ const { utcToJulianUt, degreesToDms, zodiacSign } = require("./utils"); const houses = (date, position) => { const julianDayUT = utcToJulianUt(date); - const { house, ...rawAxes } = swisseph.swe_houses( + + const withoutGeoposition = !position.latitude || !position.longitude; + + if (withoutGeoposition) { + return { + axes: { + asc: undefined, + dc: undefined, + mc: undefined, + ic: undefined + }, + houses: [] + }; + } + + const { house: housesPositions } = swisseph.swe_houses( julianDayUT, position.latitude, position.longitude, - "P" + "P" // placidus system... ); + const houseCollection = housesPositions.map((cuspid) => ({ position: degreesToDms(cuspid), sign: zodiacSign(cuspid) })); + const axes = { - asc: { - position: degreesToDms(rawAxes.ascendant), - sign: zodiacSign(rawAxes.ascendant), - }, - dc: { - position: degreesToDms(rawAxes.ascendant + 180), - sign: zodiacSign(rawAxes.ascendant + 180), - }, - mc: { - position: degreesToDms(rawAxes.mc), - sign: zodiacSign(rawAxes.mc), - }, - ic: { - position: degreesToDms(rawAxes.mc + 180), // this should to be equal to mc but with opposite sign - sign: zodiacSign(rawAxes.mc + 180), - }, + asc: houseCollection[0], dc: houseCollection[6], mc: houseCollection[9], ic: houseCollection[3] }; return { axes, - houses: Array.from(house).map((cuspid) => ({ - position: degreesToDms(cuspid), - sign: zodiacSign(cuspid), - })), + houses: houseCollection, }; }; diff --git a/src/astrologer/utils.js b/src/astrologer/utils.js index b91484b..e30cc5f 100644 --- a/src/astrologer/utils.js +++ b/src/astrologer/utils.js @@ -14,20 +14,14 @@ const utcToJulianUt = (utcDate) => { return julianDayUT; }; -const degreesToDms = (longitude) => { - const degrees = Math.floor(longitude); - - const decimals = longitude - degrees; - - const minutes = Math.floor(decimals * 60); - - const seconds = Math.round((decimals * 60 - minutes) * 60); +const degreesToDms = (value) => { + const { degree: degrees, min: minutes, second: seconds } = swisseph.swe_split_deg(value, swisseph.SE_SPLIT_DEG_ZODIACAL); return { - degrees: degrees % 30, + degrees, minutes, seconds, - longitude, + longitude: value }; }; diff --git a/test/features/empty-houses-and-axes-when-not-send-geoposition.test.js b/test/features/empty-houses-and-axes-when-not-send-geoposition.test.js new file mode 100644 index 0000000..5e91c63 --- /dev/null +++ b/test/features/empty-houses-and-axes-when-not-send-geoposition.test.js @@ -0,0 +1,39 @@ +const request = require("supertest"); +const app = require("./../../app"); + +describe("Get houses empty and axes as undefined when geolocation is not send", () => { + let response; + + beforeEach(async () => { + response = await request(app) + .get("/horoscope") + .query({ + time: "1991-07-06T16:50:00-04:00", + }) + .send(); + }); + + it("/horoscope return the AC axis (cuspid of the house I) equal to undefined", () => { + expect(response.body.data.axes.asc).toBeUndefined(); + }); + + it("/horoscope return the DC axis (cuspid of the house VII) equal to undefined", () => { + expect(response.body.data.axes.dc).toBeUndefined(); + }); + + it("/horoscope return the IC axis (cuspid of the house IV) equal to undefined", () => { + expect(response.body.data.axes.ic).toBeUndefined(); + }); + + it("/horoscope return the MC axis (cuspid of the house X) equal to undefined", () => { + expect(response.body.data.axes.mc).toBeUndefined(); + }); + + it("/horoscope return the MC axis (cuspid of the house X) equal to undefined", () => { + expect(response.body.data.axes.mc).toBeUndefined(); + }); + + it("/horoscope return the houses elements empty", () => { + expect(response.body.data.houses.length).toBe(0); + }); +}); diff --git a/test/features/get-houses-cuspids-in-placidus-system.spec.js b/test/features/get-houses-cuspids-in-placidus-system.spec.js index 4729ba1..c636cbf 100644 --- a/test/features/get-houses-cuspids-in-placidus-system.spec.js +++ b/test/features/get-houses-cuspids-in-placidus-system.spec.js @@ -31,23 +31,23 @@ describe("Get placidus houses system cuspids for 1991-07-06T16:50:00-04:00", () }; it("/horoscope return the ASC axis (cuspid of the house I)", () => { - expectCuspids(response.body.data.axes.asc, 10, 2, 32, 30); + expectCuspids(response.body.data.axes.asc, 10, 2, 32, 29); }); it("/horoscope return the DC axis (cuspid of the house VII)", () => { - expectCuspids(response.body.data.axes.dc, 4, 2, 32, 30); + expectCuspids(response.body.data.axes.dc, 4, 2, 32, 29); }); it("/horoscope return the MC axis (cuspid of the house X)", () => { - expectCuspids(response.body.data.axes.mc, 6, 14, 58, 47); + expectCuspids(response.body.data.axes.mc, 6, 14, 58, 46); }); it("/horoscope return the IC axis (cuspid of the house IV)", () => { - expectCuspids(response.body.data.axes.ic, 12, 14, 58, 47); + expectCuspids(response.body.data.axes.ic, 12, 14, 58, 46); }); it("/horoscope response has cuspid of house I", () => { - expectCuspids(response.body.data.houses[0], 10, 2, 32, 30); + expectCuspids(response.body.data.houses[0], 10, 2, 32, 29); }); it("/horoscope response has cuspid of house II", () => { @@ -55,11 +55,11 @@ describe("Get placidus houses system cuspids for 1991-07-06T16:50:00-04:00", () }); it("/horoscope response has cuspid of house III", () => { - expectCuspids(response.body.data.houses[2], 11, 17, 16, 24); + expectCuspids(response.body.data.houses[2], 11, 17, 16, 23); }); it("/horoscope response has cuspid of house IV", () => { - expectCuspids(response.body.data.houses[3], 12, 14, 58, 47); + expectCuspids(response.body.data.houses[3], 12, 14, 58, 46); }); it("/horoscope response has cuspid of house V", () => { @@ -71,7 +71,7 @@ describe("Get placidus houses system cuspids for 1991-07-06T16:50:00-04:00", () }); it("/horoscope response has cuspid of house VII", () => { - expectCuspids(response.body.data.houses[6], 4, 2, 32, 30); + expectCuspids(response.body.data.houses[6], 4, 2, 32, 29); }); it("/horoscope response has cuspid of house VIII", () => { @@ -79,11 +79,11 @@ describe("Get placidus houses system cuspids for 1991-07-06T16:50:00-04:00", () }); it("/horoscope response has cuspid of house IX", () => { - expectCuspids(response.body.data.houses[8], 5, 17, 16, 24); + expectCuspids(response.body.data.houses[8], 5, 17, 16, 23); }); it("/horoscope response has cuspid of house X", () => { - expectCuspids(response.body.data.houses[9], 6, 14, 58, 47); + expectCuspids(response.body.data.houses[9], 6, 14, 58, 46); }); it("/horoscope response has cuspid of house XI", () => { diff --git a/test/features/get-planets-positions-for-06-07-1991-205000gmt.spec.js b/test/features/get-planets-positions-for-06-07-1991-205000gmt.spec.js index e45adb5..ad39c5e 100644 --- a/test/features/get-planets-positions-for-06-07-1991-205000gmt.spec.js +++ b/test/features/get-planets-positions-for-06-07-1991-205000gmt.spec.js @@ -38,11 +38,11 @@ describe("Get the planets position for 1991-07-06T16:50:00-04:00", () => { }); test("get the mercury position", async () => { - expectAstro("mercury", 5, { degrees: 4, minutes: 28, seconds: 24 }); + expectAstro("mercury", 5, { degrees: 4, minutes: 28, seconds: 23 }); }); test("get the venus position", async () => { - expectAstro("venus", 5, { degrees: 27, minutes: 7, seconds: 59 }); + expectAstro("venus", 5, { degrees: 27, minutes: 7, seconds: 58 }); }); test("get the mars position", async () => { @@ -50,11 +50,11 @@ describe("Get the planets position for 1991-07-06T16:50:00-04:00", () => { }); test("get the jupiter position", async () => { - expectAstro("jupiter", 5, { degrees: 15, minutes: 32, seconds: 20 }); + expectAstro("jupiter", 5, { degrees: 15, minutes: 32, seconds: 19 }); }); test("get the saturn position", async () => { - expectAstro("saturn", 11, { degrees: 4, minutes: 57, seconds: 18 }); + expectAstro("saturn", 11, { degrees: 4, minutes: 57, seconds: 17 }); }); test("get the uranus position", async () => { @@ -66,11 +66,11 @@ describe("Get the planets position for 1991-07-06T16:50:00-04:00", () => { }); test("get the pluto position", async () => { - expectAstro("pluto", 8, { degrees: 17, minutes: 41, seconds: 50 }); + expectAstro("pluto", 8, { degrees: 17, minutes: 41, seconds: 49 }); }); test("get the chiron position", async () => { - expectAstro("chiron", 4, { degrees: 28, minutes: 18, seconds: 1 }); + expectAstro("chiron", 4, { degrees: 28, minutes: 18, seconds: 0 }); }); test("get the lilith position", async () => { @@ -78,7 +78,7 @@ describe("Get the planets position for 1991-07-06T16:50:00-04:00", () => { }); test("get the ceres position", async () => { - expectAstro("ceres", 7, { degrees: 23, minutes: 37, seconds: 23 }); + expectAstro("ceres", 7, { degrees: 23, minutes: 37, seconds: 22 }); }); test("get the pallas position", async () => { diff --git a/test/units/calculate-the-planets-position.test.js b/test/units/calculate-the-planets-position.test.js index ceb12dd..92bf6fd 100644 --- a/test/units/calculate-the-planets-position.test.js +++ b/test/units/calculate-the-planets-position.test.js @@ -8,7 +8,7 @@ describe("Calculate the planets position in a moment", () => { expect(sun.position.degrees).toBe(4); expect(sun.sign).toBe(12); expect(sun.position.minutes).toBe(0); - expect(sun.position.seconds).toBe(19); + expect(sun.position.seconds).toBe(18); }); it("get the uranus position at 2020-02-23T01:17:13-03:00", async () => { @@ -16,7 +16,7 @@ describe("Calculate the planets position in a moment", () => { expect(uranus.position.degrees).toBe(3); expect(uranus.sign).toBe(2); expect(uranus.position.minutes).toBe(26); - expect(uranus.position.seconds).toBe(6); + expect(uranus.position.seconds).toBe(5); }); it("get the moon position at 2020-02-23T01:17:13-03:00", async () => { @@ -32,6 +32,6 @@ describe("Calculate the planets position in a moment", () => { expect(mercury.position.degrees).toBe(9); expect(mercury.sign).toBe(12); expect(mercury.position.minutes).toBe(50); - expect(mercury.position.seconds).toBe(56); + expect(mercury.position.seconds).toBe(55); }); }); diff --git a/test/units/transform-lontitude-to-dms.test.js b/test/units/transform-lontitude-to-dms.test.js new file mode 100644 index 0000000..4bd0520 --- /dev/null +++ b/test/units/transform-lontitude-to-dms.test.js @@ -0,0 +1,11 @@ +const { degreesToDms } = require("./../../src/astrologer/utils"); + +describe("Transform longitude degrees to dms", () => { + it("transform 270 to 270ยบ0'0\"", () => { + const result = degreesToDms(270); + expect(result.degrees).toBe(0); + expect(result.longitude).toBe(270); + expect(result.minutes).toBe(0); + expect(result.seconds).toBe(0); + }); +});