Skip to content

Commit

Permalink
Return empty houses and axes when not has position
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuphi committed Oct 6, 2020
1 parent e8e99c6 commit b4c99b7
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 52 deletions.
43 changes: 21 additions & 22 deletions src/astrologer/houses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand Down
14 changes: 4 additions & 10 deletions src/astrologer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
20 changes: 10 additions & 10 deletions test/features/get-houses-cuspids-in-placidus-system.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,35 @@ 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", () => {
expectCuspids(response.body.data.houses[1], 10, 24, 11, 43);
});

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", () => {
Expand All @@ -71,19 +71,19 @@ 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", () => {
expectCuspids(response.body.data.houses[7], 4, 24, 11, 43);
});

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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ 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 () => {
expectAstro("mars", 5, { degrees: 24, minutes: 42, seconds: 10 });
});

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 () => {
Expand All @@ -66,19 +66,19 @@ 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 () => {
expectAstro("lilith", 10, { degrees: 7, minutes: 58, seconds: 51 });
});

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 () => {
Expand Down
6 changes: 3 additions & 3 deletions test/units/calculate-the-planets-position.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 () => {
const uranus = await astrologer.position("uranus", 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 () => {
Expand All @@ -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);
});
});
11 changes: 11 additions & 0 deletions test/units/transform-lontitude-to-dms.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit b4c99b7

Please sign in to comment.