Breeze / breeze.js.samples

Breeze JavaScript Client sample applications
MIT License
96 stars 85 forks source link

fixed logical bug on 2 specs in queryTests.js #20

Closed TheHalcyonSavant closed 9 years ago

TheHalcyonSavant commented 9 years ago

Test fails in queryTests.js on both specs: "on orders ordered after April '98 OR with freight > 100" "orders ordered after April '98 AND with freight > 100" The they're failing because JavaScript Date.toISOString() method is somewhat ambiguous: new Date(1998, 3, 1).toISOString() returns "1998-03-31T22:00:00.000Z" This means that orders with OrderDate = "1998-04-01" are also included with the queries.

To test this claim run this SQL on the server: SELECT * FROM [Northwind].[dbo].[Order] where Freight > 100 and OrderDate > '1998-03-31T22:00:00.000Z' This query should return 16 instead of 15 records.

wardbell commented 9 years ago

You've definitely identified an issue but I don't think your solution hits the mark. The problem is that new Date(1998, 3,1) produced a date in local time. The values in the database are in GMT. Breeze converts the datetime with toISOString which gives an unpredictable result that is either on March 31 or April 1 depending upon when you run it.

As it happens, I always ran the tests at a convenient time so the tests always passed for me with 15. You ran your tests at a time which resulted in 16 records.

The solution isn't to change the expect value. It's to lock in the right datetime.

I've updated the tests to construct the testDate in UTC. For example:

    // Make sure date is in UTC (like the datetimes in the database)
    var testDate = new Date(Date.UTC(1998, 3, 1)); // month counts from zero!

To illustrate the point, see the following output that was run around 4:47 PM PST.

> new Date(1998, 3, 1).toISOString() // the way we had it was not good
'1998-04-01T07:00:00.000Z'

> // Make sure date is in UTC (like the datetimes in the database)
> var testDate = new Date(Date.UTC(1998, 3, 1)); // month counts from zero!

> testDate
Tue Mar 31 1998 17:00:00 GMT-0700 (Pacific Daylight Time)
> testDate.toISOString() // after Breeze gets done with it
'1998-04-01T00:00:00.000Z'

See how we get a stable, GMT comparison date no matter when I run the tests on my machine.

I made this correction throughout queryTests.js (there were more than two places where I got this wrong).