diff --git a/app/services/neopets/nc_mall.rb b/app/services/neopets/nc_mall.rb index 9795edfd..84b2c5ec 100644 --- a/app/services/neopets/nc_mall.rb +++ b/app/services/neopets/nc_mall.rb @@ -136,14 +136,15 @@ module Neopets::NCMall end # Given item info, return a hash of discount-specific info, if any. + NST = Time.find_zone("Pacific Time (US & Canada)") def self.parse_item_discount(item_info) discount_price = item_info["discountPrice"] return nil unless discount_price.present? && discount_price > 0 { price: discount_price, - begins_at: item_info["discountBegin"], - ends_at: item_info["discountEnd"], + begins_at: NST.at(item_info["discountBegin"]), + ends_at: NST.at(item_info["discountEnd"]), } end diff --git a/spec/services/nc_mall_spec.rb b/spec/services/nc_mall_spec.rb index eefea8d0..b9d8b26a 100644 --- a/spec/services/nc_mall_spec.rb +++ b/spec/services/nc_mall_spec.rb @@ -2,6 +2,52 @@ require 'webmock/rspec' require_relative '../rails_helper' RSpec.describe Neopets::NCMall, type: :model do + describe ".load_page" do + def stub_page_request + stub_request(:get, "https://ncmall.neopets.com/mall/ajax/load_page.phtml?type=new&cat=52&lang=en"). + with( + headers: { + "User-Agent": Rails.configuration.user_agent_for_neopets, + }, + ) + end + + subject(:page) do + Neopets::NCMall.load_page("new", 52) + end + + it "loads a page from the NC Mall" do + stub_page_request.to_return( + body: '{"html":"","render_html":"0","render":[82936,90226],"object_data":{"82936":{"id":82936,"name":"+1 Extra Pet Slot","description":"Just ONE more Neopet... just ONE more...! This pack includes 1 extra pet slot. Each extra pet slot can be used to create a new pet, adopt a pet, or bring back any idle pets lost from non-premium accounts.","price":500,"discountPrice":0,"atPurchaseDiscountPrice":null,"discountBegin":1735372800,"discountEnd":1735718399,"uses":1,"isSuperpack":0,"isBundle":0,"packContents":null,"isAvailable":1,"imageFile":"mall_petslots_1","saleBegin":1703094300,"saleEnd":0,"duration":0,"isSoldOut":0,"isNeohome":0,"isWearable":0,"isBuyable":1,"isAlbumTheme":0,"isGiftbox":0,"isInRandomWindow":null,"isElite":0,"isCollectible":0,"isKeyquest":0,"categories":null,"isHabitarium":0,"isNoInvInsert":1,"isLimitedQuantity":0,"isPresale":0,"isGambling":0,"petSlotPack":1,"maxPetSlots":10,"currentUserBoughtPetSlots":0,"formatted":{"name":"+1 Extra Pet Slot","ck":false,"price":"500","discountPrice":"0","limited":false},"converted":true},"90226":{"id":90226,"name":"Weekend Sales 2025 Mega Gram","description":"Lets go shopping! Purchase this Weekend Sales Mega Gram and choose from exclusive Weekend Sales items to send to a Neofriend, no gift box needed! This gram also has a chance of including a Limited Edition NC item. Please visit the NC Mall FAQs for more information on this item.","price":250,"discountPrice":125,"atPurchaseDiscountPrice":null,"discountBegin":1737136800,"discountEnd":1737446399,"uses":1,"isSuperpack":0,"isBundle":0,"packContents":null,"isAvailable":1,"imageFile":"42embjc204","saleBegin":1737136800,"saleEnd":1739865599,"duration":0,"isSoldOut":0,"isNeohome":0,"isWearable":0,"isBuyable":1,"isAlbumTheme":0,"isGiftbox":0,"isInRandomWindow":null,"isElite":0,"isCollectible":0,"isKeyquest":0,"categories":null,"isHabitarium":0,"isNoInvInsert":0,"isLimitedQuantity":0,"isPresale":0,"isGambling":0,"formatted":{"name":"Weekend Sales 2025 Mega Gram","ck":false,"price":"250","discountPrice":"125","limited":false},"converted":true}},"response":{"category":"52","type":"new","image":{"location":"//images.neopets.com/items/","star_location":"//images.neopets.com/ncmall/","extension":".gif","stars":{"blue":"star_blue","red":"star_red","orange":"star_orange","leso":"leso_star"}},"heading":"New","no_items_msg":"","shopkeeper":{"img":"//images.neopets.com/ncmall/shopkeepers/mall_new.jpg","title":"Style is all about what\'s new… good thing that\'s all I stock!","message":"Come browse my shop and find the latest and greatest the NC Mall has to offer!","new_format":true},"strings":{"claim_it":"Claim it","none_left":"Sorry, there are none left!","nc":"NC","free":"FREE","add_to_cart":"Add to cart"}}}' + ) + + expect(page[:items]).to contain_exactly( + { + id: 82936, + name: "+1 Extra Pet Slot", + description: "Just ONE more Neopet... just ONE more...! This pack includes 1 extra pet slot. Each extra pet slot can be used to create a new pet, adopt a pet, or bring back any idle pets lost from non-premium accounts.", + price: 500, + discount: nil, + is_available: true, + }, + { + id: 90226, + name: "Weekend Sales 2025 Mega Gram", + description: "Lets go shopping! Purchase this Weekend Sales Mega Gram and choose from exclusive Weekend Sales items to send to a Neofriend, no gift box needed! This gram also has a chance of including a Limited Edition NC item. Please visit the NC Mall FAQs for more information on this item.", + price: 250, + discount: { + price: 125, + begins_at: Time.find_zone("Pacific Time (US & Canada)"). + local(2025, 1, 17, 10), + ends_at: Time.find_zone("Pacific Time (US & Canada)"). + local(2025, 1, 20, 23, 59, 59), + }, + is_available: true, + }, + ) + end + end + describe ".load_styles" do def stub_styles_request(tab:) stub_request(:post, "https://www.neopets.com/np-templates/ajax/stylingstudio/studio.php").