1
1

00:00:01,210  -->  00:00:03,180
<v Jose>Hi and and welcome back. In this video, we're going</v>
2

2

00:00:03,180  -->  00:00:07,550
to test our app with the new stores. Now we don't have
3

3

00:00:07,550  -->  00:00:10,580
a way to create stores through the web yet, so we're
4

4

00:00:10,580  -->  00:00:13,570
gonna have to add them into our database manually.
5

5

00:00:13,570  -->  00:00:15,450
We're just gonna do one to make sure that everything's
6

6

00:00:15,450  -->  00:00:18,520
working, and what we're gonna do first is we're gonna make
7

7

00:00:18,520  -->  00:00:20,650
sure that we starting off with a clean slate.
8

8

00:00:20,650  -->  00:00:23,700
So we're going to remove all items and all alerts
9

9

00:00:23,700  -->  00:00:26,400
from our database up to this point in time, so that
10

10

00:00:26,400  -->  00:00:29,610
we don't get anything mixed up moving forward.
11

11

00:00:29,610  -->  00:00:33,600
So db.items.remove and make sure to put an empty
12

12

00:00:33,600  -->  00:00:35,270
set of of curly braces inside the remove.
13

13

00:00:35,270  -->  00:00:36,930
It's gonna remove everything.
14

14

00:00:36,930  -->  00:00:40,417
Db.alerts.remove is going to remove everything.
15

15

00:00:40,417  -->  00:00:43,070
Oh do make sure, by the way I haven't done this but
16

16

00:00:43,070  -->  00:00:46,500
use your database first. So use the database that
17

17

00:00:46,500  -->  00:00:50,610
you have in your application and then do this
18

18

00:00:50,610  -->  00:00:53,320
and there we have it, now we're removing stuff.
19

19

00:00:53,320  -->  00:00:57,710
And so once you've done that, I'm going to also remove all
20

20

00:00:57,710  -->  00:01:00,080
my stores in case I do have any, no I don't, that's
21

21

00:01:00,080  -->  00:01:03,310
good. And then we're going to create a new store.
22

22

00:01:03,310  -->  00:01:08,310
We're gonna insert. So that's db.stores.insert.
23

23

00:01:08,350  -->  00:01:11,470
And then inside brackets, we're gonna put in the
24

24

00:01:11,470  -->  00:01:14,880
necessary information for this store which is
25

25

00:01:14,880  -->  00:01:17,800
_id is gonna be anything you want, it doesn't have
26

26

00:01:17,800  -->  00:01:21,530
to be a UU id, it can be anything. And then the name
27

27

00:01:21,530  -->  00:01:23,590
which is gonna be something you like, John Lewis in
28

28

00:01:23,590  -->  00:01:25,789
my case, the URL prefix which is gonna be
29

29

00:01:25,789  -->  00:01:30,789
https://www.johnlewis.com/
30

30

00:01:31,220  -->  00:01:35,190
the tag name which is going to be P for the paragraph tag
31

31

00:01:35,190  -->  00:01:38,510
that contains the price in John lewis and then the query
32

32

00:01:38,510  -->  00:01:42,120
is going to be another object in JavaScript which has
33

33

00:01:42,120  -->  00:01:45,780
a class of price price--large
34

34

00:01:46,640  -->  00:01:48,820
So as you can see that contains everything we need to
35

35

00:01:48,820  -->  00:01:53,070
find item prices. And this is going to be linked in the
36

36

00:01:53,070  -->  00:01:55,640
resources section so you don't have to type it out yourself
37

37

00:01:55,640  -->  00:01:58,540
you can copy and paste it and it's totally cool.
38

38

00:01:58,540  -->  00:02:02,200
And so we don't make any mistakes. Now that's one
39

39

00:02:02,200  -->  00:02:05,540
row inserted and we don't have any items or any alerts.
40

40

00:02:05,540  -->  00:02:09,740
So what we have to do now is we have to go and find an
41

41

00:02:09,740  -->  00:02:12,360
item that we're interested in John Lewis and we're gonna
42

42

00:02:12,360  -->  00:02:16,240
create an alert through our web. So let's do that.
43

43

00:02:16,240  -->  00:02:18,850
First of all, make sure MongoDB is running, which it should
44

44

00:02:18,850  -->  00:02:22,586
be and then run your app, and again we now only have
45

45

00:02:22,586  -->  00:02:26,803
the ability to create alerts. We don't have anything else.
46

46

00:02:27,700  -->  00:02:31,000
So our alert form looks like this, has an item URL,
47

47

00:02:31,000  -->  00:02:33,806
I'm gonna put in my iPad Pro there, and then the price
48

48

00:02:33,806  -->  00:02:36,320
limit for something you're interested in.
49

49

00:02:36,320  -->  00:02:39,760
This iPad pro is something like nine million pounds
50

50

00:02:39,760  -->  00:02:42,850
and so I'm going to put five thousand in there so that
51

51

00:02:42,850  -->  00:02:46,580
it will tell me "hey this is under your desired price."
52

52

00:02:46,580  -->  00:02:49,620
Not that anybody should spend five grand on an iPad,
53

53

00:02:49,620  -->  00:02:52,880
but you know. So what that's done in the background is
54

54

00:02:52,880  -->  00:02:57,810
it's gone ahead and it has taken the item URL we've passed,
55

55

00:02:57,810  -->  00:03:02,650
we've found a store with that URL which again uses only the
56

56

00:03:02,650  -->  00:03:06,320
first part of it. And presumably it's found the store
57

57

00:03:06,320  -->  00:03:09,630
that we've created, then it's created an item with that URL
58

58

00:03:09,630  -->  00:03:13,210
on the stores tag name and query, saved it to MongoDB
59

59

00:03:13,210  -->  00:03:16,450
and then created an alert and also saved it to MongoDB.
60

60

00:03:16,450  -->  00:03:19,890
Now we can stop our app. Then we go over to our alert
61

61

00:03:19,890  -->  00:03:23,405
updater. And remember, this alert updater file is going to
62

62

00:03:23,405  -->  00:03:28,405
load the item price and that is going to use the item
63

63

00:03:28,630  -->  00:03:32,690
that it loads up here. Remember, we still got the item
64

64

00:03:32,690  -->  00:03:35,360
module, we're still using the item module, it contains
65

65

00:03:35,360  -->  00:03:38,220
a bunch of useful things like loading prices from the
66

66

00:03:38,220  -->  00:03:42,837
website. So that is going to then go and load the price
67

67

00:03:42,837  -->  00:03:46,970
using the store's tag name and query that we've already
68

68

00:03:46,970  -->  00:03:50,970
saved into this item. So what we're gonna do is we're
69

69

00:03:50,970  -->  00:03:53,070
gonna run the alert of data, so I'm right clicking
70

70

00:03:53,070  -->  00:03:54,730
alert of data, pressing run
71

71

00:03:56,247  -->  00:03:59,210
and there we have our first bug.
72

72

00:03:59,210  -->  00:04:03,330
So good, we're always gonna find some bugs in our
73

73

00:04:03,330  -->  00:04:06,890
applications. This first bug that we've got here is
74

74

00:04:06,890  -->  00:04:09,193
because when we created an alert,
75

75

00:04:10,870  -->  00:04:12,700
this is a string and it
76

76

00:04:12,700  -->  00:04:15,730
comes from the web,
77

77

00:04:15,730  -->  00:04:17,390
not a number.
78

78

00:04:17,390  -->  00:04:21,230
So the price that the items found on the website is
79

79

00:04:21,230  -->  00:04:24,130
converted into a float, but the number that I stored in
80

80

00:04:24,130  -->  00:04:27,230
our database is not converted into a float, it is a string.
81

81

00:04:27,230  -->  00:04:32,230
So we do have to turn this into a float before we save it
82

82

00:04:33,000  -->  00:04:35,930
to our database. Okay, that's totally fine.
83

83

00:04:35,930  -->  00:04:38,670
What do we have to do now that we found a bug in our alert
84

84

00:04:38,670  -->  00:04:43,130
creation? Go into the database, delete the alert and then
85

85

00:04:43,130  -->  00:04:45,580
go and recreate it. So let me do that real quick.
86

86

00:04:46,810  -->  00:04:49,990
Good, I've gone recreated my alert, now hopefully it is
87

87

00:04:49,990  -->  00:04:52,523
all correct, we can run our alert updater again.
88

88

00:04:53,680  -->  00:04:57,770
And there we have it. This item has reached a price under
89

89

00:04:57,770  -->  00:05:02,270
five thousand, the latest price is 1469.0.
90

90

00:05:02,270  -->  00:05:05,940
Still expensive. (laughs) So there you have it,
91

91

00:05:05,940  -->  00:05:09,150
very important to be testing things out as you go along
92

92

00:05:09,150  -->  00:05:11,680
so that you can find bugs precisely like that one,
93

93

00:05:11,680  -->  00:05:13,490
maybe you realised that this should have been a float
94

94

00:05:13,490  -->  00:05:16,930
earlier on, I know I did like 10 videos ago and then
95

95

00:05:16,930  -->  00:05:21,010
I forgot to add it in, and so that's cool, you've found a
96

96

00:05:21,010  -->  00:05:24,110
bug, we fix it and we move on forwards.
97

97

00:05:24,110  -->  00:05:26,270
Now that we've parted this out, we know that our
98

98

00:05:26,270  -->  00:05:30,610
stores idea is going to work. So we can allow users
99

99

00:05:30,610  -->  00:05:35,240 line:15% 
now to create new stores using our website.
100

100

00:05:35,240  -->  00:05:37,200 line:15% 
We're gonna be doing that over the next few videos,
101

101

00:05:37,200  -->  00:05:38,300
so I'll see you there.
