"use strict";

// set the timeout of these tests to 10 seconds
jasmine.getEnv().defaultTimeoutInterval = 10000;

var PriceFinder = require("../../lib/price-finder"),
    priceFinder = new PriceFinder();

function verifyPrice(price) {
    expect(price).toBeDefined();
    // we can't guarantee the price, so just make sure it's a number
    // that's more than -1
    expect(price).toBeGreaterThan(-1);
}

function verifyName(actualName, expectedName) {
    expect(actualName).toEqual(expectedName);
}

function verifyCategory(actualCategory, expectedCategory) {
    expect(actualCategory).toEqual(expectedCategory);
}

describe("price-finder for Crutchfield Store URIs", function() {

    // Television & Video
    describe("testing a Television & Video item", function() {
        // Samsung Blu-ray Player
        var uri = "http://www.crutchfield.com/p_305BDF5700/Samsung-BD-F5700.html";

        it("should respond with a price for findItemPrice()", function(done) {
            priceFinder.findItemPrice(uri, function(err, price) {
                expect(err).toBeNull();
                verifyPrice(price);
                done();
            });
        });

        it("should respond with a price, and the right category and name for findItemDetails()", function(done) {
            priceFinder.findItemDetails(uri, function(err, itemDetails) {
                expect(err).toBeNull();
                expect(itemDetails).toBeDefined();

                verifyPrice(itemDetails.price);
                verifyName(itemDetails.name, "Samsung BD-F5700");
                verifyCategory(itemDetails.category, "Television & Video");

                done();
            });
        });
    });

    // Home Audio
    describe("testing a Home Audio item", function() {
        // Marantz Receiver
        var uri = "http://www.crutchfield.com/p_642NR1403/Marantz-NR1403.html";

        it("should respond with a price for findItemPrice()", function(done) {
            priceFinder.findItemPrice(uri, function(err, price) {
                expect(err).toBeNull();
                verifyPrice(price);
                done();
            });
        });

        it("should respond with a price, and the right category and name for findItemDetails()", function(done) {
            priceFinder.findItemDetails(uri, function(err, itemDetails) {
                expect(err).toBeNull();
                expect(itemDetails).toBeDefined();

                verifyPrice(itemDetails.price);
                verifyName(itemDetails.name, "Marantz NR1403");
                verifyCategory(itemDetails.category, "Home Audio");

                done();
            });
        });
    });

});

@@ -854,17 +854,17 @@
 /p_305BD
-F
+J
 5700/Sam
@@ -871,17 +871,17 @@
 sung-BD-
-F
+J
 5700.htm
@@ -1544,17 +1544,17 @@
 sung BD-
-F
+J
 5700%22);%0A

Update item in crutchfield e2e test