hello and welcome to bitfumes this is
the level 8 test driven api i'm your
host sarthak before moving forward i
just want to thank api artisan for their
amazing tool which is going to convert
the sql file with all the databases
structure directly into the api with the
swagger documentation so if you want to
create your own laravel api instantly
then check out this apison.com website
now let's start the video
now we don't want this so i
am going to remove it and what next we
need a test file so
file so comes
i can say
file to upload
and this should come somewhere
okay
now what will be the
the scene or the scenario first
uh
we need to
fetch
last
seven days of tasks
then
create a json file with this data the
seven days data
then
zip create a zip file create a zip
file with this json file
and then send this zip to
drive this is the scenario we
want
now
first we need to fetch the last seven
day tasks so it's very easy tasks
is equal to
task
where
created at is
greater than equal to
now
and after that i need to say
subtract days
how many days seven days
and finally we need to get it like here
so let's dive dump
tas
open the
service test and here we are checking
for that route
now if i run it
it's going to give us empty because in
our testing we don't have any task
so let's create task
and here i i'm just going to say created
at is
now
and
subtracting days
how many days starting with two days
then three
then four
and then i'm going to return 10. so
these three comes under the seven days
so maybe one let's keep it six
these comes under seven days and this
one will not so we should see
uh four results yeah
so let's see how many results we are
getting we are getting four result
that's right
so first part is done we have fetched
the data next we need to actually
convert this into a json file so let's
go
do this create a json file so let's use
a storage
and storage should be
eliminate storage facade
putting
uh
let's say task
dump
okay
and dot json
and the content is going to be the tasks
convert everything into json so i say to
json
and how this is going to look let me
show you
okay
so this will be like this okay that's
right
now we have done with this
okay
can we do without like
directly we can do
instead of this i can can i say to json
directly
no i need to first get it then do this
anyways so if i run this file
this is going to create the file but we
have error it says path cannot be empty
what happened
so i think this should be slash public
slash
and
path and yeah so nice
let's try
one more time it says path cannot be
empty what happened
in the storage app
all we already have this actually
so task dump dot json we already have it
and if i
format it one two three and four we're
only getting four data which we are
expecting right like this
okay next we have done with this we have
created the file
okay now what i can do i can say
json file name
name
is equal to
this one
and i'm going to use double quotes
so that i can use
the
the variable name inside this string
like here
oops that should be string
done
now finally we have to create a zip file
with this
json data
how we can create a zip file we first
need to create a
zip
using the
php zip archive
once we are done with this
let's create a zip file name so zip file
name just the file name you want to give
so i'm going to use the timestamp so
timestamp
and concatenating this with the
task.zip
and this should create the file name
after that i need to check
first
i'm going to open this
the zip file name which i have created
and i'm going to say zip archive
created
so
create so if this is going to be true
that means if
zipper or zip archive can create
uh this
name file
we can able to create this name file
then we can simply say zip add
file
inside this and which file this
json
name adjacent file name okay
before that since we need to give a
proper file path so if i show you like
here so first file path we need to give
so let's
search and see
what exactly the file path is so it's
actually inside storage app public and
then we have this task dump
you can use any other path it's up to
you so storage path
inside that i say app
public
and
this json file name so let's run this
test and see exactly what we are getting
we are getting storage app public and
after public we need a slash
this is going to work
yes nice
okay so this is going to be the real
path
so
i can say
file path is equal to this
and then i provide the file path
like this
and once we are done with this i just
need to say zip close
then it will only going to create the
zip file
let's see where this is going to create
the zip file
run this test
and this test is complaining about some
kind of path cannot be empty which is
because of this thing
but
if you see
on our base
path we have this
zip file created
that's amazing
now we just need to give the path of
this zip file and i don't want to move
that inside here i want to put that file
inside the storage
app
and why not create a
temporary directory which will going to
hold this json and the zip and after
that we will clear that directory also
so this means inside public
maybe i can say temp directory
and that will move this json file
for this file name i'm storage i'm going
to use the storage path same as before
so this is going to be app
public
temp
and
then concatenating this thing this will
become the file name
and since we have moved it to temp
we can do something like this
okay
and then it should move both of these
file into that so i'm going to remove
this and already removed that zip file
let's run it
okay so we are not getting that temp
file inside zip file inside the temp so
that is because we need to say slash
here
okay so one more time i'm going to
remove this and the temp file folder
run it
and
yes we can see we have both here inside
it
now as we know we need to send this file
to the drive
so we have done all these things
and
file to upload now file to upload will
be the
file
zip file name we already have
okay so file to upload will come here
like this
and now if i run it
it's going to pass that's really amazing
so since we have done all these things
to upload
now it's time really to check if it is
working fine or not
so let's move to the postman and do all
the or test all the api we have created
yet