|
1 | | -import server from '../server'; |
| 1 | +import server from '../server'; |
2 | 2 | import supertest from 'supertest'; |
3 | 3 | import resizeImage from '../utilize/sharp'; |
4 | 4 | import { getImageMetaData } from '../utilize/sharp'; |
5 | 5 |
|
6 | | -const response = supertest ( server ) ; |
| 6 | +const response = supertest(server); |
7 | 7 |
|
8 | | - |
9 | | -describe('these tests are focused at the validate middleware a failure tests at /api/image/?' , ()=>{ |
| 8 | +describe('these tests are focused at the validate middleware a failure tests at /api/image/?', () => { |
10 | 9 | const queriesSchema = { |
11 | | - allNull : '', |
12 | | - onlyNameAndWrong : '?name=ahmedzein', |
| 10 | + allNull: '', |
| 11 | + onlyNameAndWrong: '?name=ahmedzein', |
13 | 12 | onlyNameAndCorrect: '?name=smtp1', |
14 | | - onlywidthAndWrong : '?width=aasd', |
15 | | - onlywidthAndCorrect : '?width=407', |
16 | | - onlyHeightAndWrong : '?height=qwe', |
17 | | - onlyHeightAndCorrect : '?height=365', |
18 | | - nameAndWidthWrong : '?name=ahmedzein&width=aasd', |
19 | | - nameAndWidthCorrect : '?name=smtp1&width=407', |
20 | | - nameAndHeightWrong :'?name=ahmedzein&height=qwe', |
21 | | - nameAndHeightCorrect :'?name=smtp1&height=365', |
22 | | - WidthAndHeightWrong : '?width=aasd&height=qwe', |
23 | | - WidthAndHeightCorrect : '?width=407&height=365', |
| 13 | + onlywidthAndWrong: '?width=aasd', |
| 14 | + onlywidthAndCorrect: '?width=407', |
| 15 | + onlyHeightAndWrong: '?height=qwe', |
| 16 | + onlyHeightAndCorrect: '?height=365', |
| 17 | + nameAndWidthWrong: '?name=ahmedzein&width=aasd', |
| 18 | + nameAndWidthCorrect: '?name=smtp1&width=407', |
| 19 | + nameAndHeightWrong: '?name=ahmedzein&height=qwe', |
| 20 | + nameAndHeightCorrect: '?name=smtp1&height=365', |
| 21 | + WidthAndHeightWrong: '?width=aasd&height=qwe', |
| 22 | + WidthAndHeightCorrect: '?width=407&height=365', |
24 | 23 | }; |
25 | | - |
26 | | - it( '1.1 Query values is null or NaN or undefined ' , async () => { |
27 | | - const responseObject = await response.get (`/api/image${queriesSchema.allNull}`); |
28 | | - expect( responseObject.status ).toEqual (400); |
29 | | - }); |
30 | | - it( '1.2 Query values only have a name value and its Wrong ' , async () => { |
31 | | - const responseObject = await response.get (`/api/image?${queriesSchema.onlyNameAndWrong}`); |
32 | | - expect( responseObject.status ).toEqual (400); |
33 | | - }); |
34 | | - it( '1.3 Query values only have a name and its Correct ' , async () => { |
35 | | - const responseObject = await response.get (`/api/image${queriesSchema.onlyNameAndCorrect}`); |
36 | | - expect( responseObject.status ).toEqual (400); |
37 | | - }); |
38 | | - it( '1.4 Query values only have a width and its Wrong' , async () => { |
39 | | - const responseObject = await response.get (`/api/image${queriesSchema.onlywidthAndWrong}`); |
40 | | - expect( responseObject.status ).toEqual (400); |
41 | | - }); |
42 | | - it( '1.5 Query values only have a width and its Correct ' , async () => { |
43 | | - const responseObject = await response.get (`/api/image${queriesSchema.onlywidthAndCorrect}`); |
44 | | - expect( responseObject.status ).toEqual (400); |
45 | | - }); |
46 | | - it( '1.6 Query values only have a height and its Wrong ' , async () => { |
47 | | - const responseObject = await response.get (`/api/image${queriesSchema.onlyHeightAndWrong}`); |
48 | | - expect( responseObject.status ).toEqual (400); |
49 | | - }); |
50 | | - it( '1.7 Query values only have a height and its Correct ' , async () => { |
51 | | - const responseObject = await response.get (`/api/image${queriesSchema.onlyHeightAndCorrect}`); |
52 | | - expect( responseObject.status ).toEqual (400); |
53 | | - }); |
54 | | - it( '1.7 Query values only have a name and width and its Wrong ' , async () => { |
55 | | - const responseObject = await response.get (`/api/image${queriesSchema.nameAndWidthWrong}`); |
56 | | - expect( responseObject.status ).toEqual (400); |
57 | | - }); |
58 | | - it( '1.8 Query values only have a name and width and its Correct ' , async () => { |
59 | | - const responseObject = await response.get (`/api/image${queriesSchema.nameAndWidthCorrect}`); |
60 | | - expect( responseObject.status ).toEqual (400); |
61 | | - }); |
62 | | - it( '1.9 Query values only have a name and height and its Wrong ' , async () => { |
63 | | - const responseObject = await response.get (`/api/image${queriesSchema.nameAndHeightWrong}`); |
64 | | - expect( responseObject.status ).toEqual (400); |
65 | | - }); |
66 | | - it( '2.0 Query values only have a name and height and its Correct ' , async () => { |
67 | | - const responseObject = await response.get (`/api/image${queriesSchema.nameAndHeightCorrect}`); |
68 | | - expect( responseObject.status ).toEqual (400); |
69 | | - }); |
70 | | - it( '2.1 Query values only have a width and height and its Wrong ' , async () => { |
71 | | - const responseObject = await response.get (`/api/image${queriesSchema.WidthAndHeightWrong}`); |
72 | | - expect( responseObject.status ).toEqual (400); |
73 | | - }); |
74 | | - it( '2.2 Query values only have a width and height and its Correct ' , async () => { |
75 | | - const responseObject = await response.get (`/api/image${queriesSchema.WidthAndHeightCorrect}`); |
76 | | - expect( responseObject.status ).toEqual (400); |
77 | | - }); |
78 | 24 |
|
| 25 | + it('1.1 Query values is null or NaN or undefined ', async () => { |
| 26 | + const responseObject = await response.get( |
| 27 | + `/api/image${queriesSchema.allNull}` |
| 28 | + ); |
| 29 | + expect(responseObject.status).toEqual(400); |
| 30 | + }); |
| 31 | + it('1.2 Query values only have a name value and its Wrong ', async () => { |
| 32 | + const responseObject = await response.get( |
| 33 | + `/api/image?${queriesSchema.onlyNameAndWrong}` |
| 34 | + ); |
| 35 | + expect(responseObject.status).toEqual(400); |
| 36 | + }); |
| 37 | + it('1.3 Query values only have a name and its Correct ', async () => { |
| 38 | + const responseObject = await response.get( |
| 39 | + `/api/image${queriesSchema.onlyNameAndCorrect}` |
| 40 | + ); |
| 41 | + expect(responseObject.status).toEqual(400); |
| 42 | + }); |
| 43 | + it('1.4 Query values only have a width and its Wrong', async () => { |
| 44 | + const responseObject = await response.get( |
| 45 | + `/api/image${queriesSchema.onlywidthAndWrong}` |
| 46 | + ); |
| 47 | + expect(responseObject.status).toEqual(400); |
| 48 | + }); |
| 49 | + it('1.5 Query values only have a width and its Correct ', async () => { |
| 50 | + const responseObject = await response.get( |
| 51 | + `/api/image${queriesSchema.onlywidthAndCorrect}` |
| 52 | + ); |
| 53 | + expect(responseObject.status).toEqual(400); |
| 54 | + }); |
| 55 | + it('1.6 Query values only have a height and its Wrong ', async () => { |
| 56 | + const responseObject = await response.get( |
| 57 | + `/api/image${queriesSchema.onlyHeightAndWrong}` |
| 58 | + ); |
| 59 | + expect(responseObject.status).toEqual(400); |
| 60 | + }); |
| 61 | + it('1.7 Query values only have a height and its Correct ', async () => { |
| 62 | + const responseObject = await response.get( |
| 63 | + `/api/image${queriesSchema.onlyHeightAndCorrect}` |
| 64 | + ); |
| 65 | + expect(responseObject.status).toEqual(400); |
| 66 | + }); |
| 67 | + it('1.7 Query values only have a name and width and its Wrong ', async () => { |
| 68 | + const responseObject = await response.get( |
| 69 | + `/api/image${queriesSchema.nameAndWidthWrong}` |
| 70 | + ); |
| 71 | + expect(responseObject.status).toEqual(400); |
| 72 | + }); |
| 73 | + it('1.8 Query values only have a name and width and its Correct ', async () => { |
| 74 | + const responseObject = await response.get( |
| 75 | + `/api/image${queriesSchema.nameAndWidthCorrect}` |
| 76 | + ); |
| 77 | + expect(responseObject.status).toEqual(400); |
| 78 | + }); |
| 79 | + it('1.9 Query values only have a name and height and its Wrong ', async () => { |
| 80 | + const responseObject = await response.get( |
| 81 | + `/api/image${queriesSchema.nameAndHeightWrong}` |
| 82 | + ); |
| 83 | + expect(responseObject.status).toEqual(400); |
| 84 | + }); |
| 85 | + it('2.0 Query values only have a name and height and its Correct ', async () => { |
| 86 | + const responseObject = await response.get( |
| 87 | + `/api/image${queriesSchema.nameAndHeightCorrect}` |
| 88 | + ); |
| 89 | + expect(responseObject.status).toEqual(400); |
| 90 | + }); |
| 91 | + it('2.1 Query values only have a width and height and its Wrong ', async () => { |
| 92 | + const responseObject = await response.get( |
| 93 | + `/api/image${queriesSchema.WidthAndHeightWrong}` |
| 94 | + ); |
| 95 | + expect(responseObject.status).toEqual(400); |
| 96 | + }); |
| 97 | + it('2.2 Query values only have a width and height and its Correct ', async () => { |
| 98 | + const responseObject = await response.get( |
| 99 | + `/api/image${queriesSchema.WidthAndHeightCorrect}` |
| 100 | + ); |
| 101 | + expect(responseObject.status).toEqual(400); |
| 102 | + }); |
79 | 103 | }); |
80 | 104 |
|
81 | 105 | describe('these tests are focused at the utilize/sharp file ', () => { |
82 | | - const testImageNameFailure = 'fjod' ; |
83 | | - const testImageWidth = 1500 ; |
84 | | - const testImageHeight = 1500 ; |
85 | | - it ('1.1 The resizeImage function,Wrong image name .toBeRejected ',async ()=>{ |
86 | | - |
87 | | - await expectAsync( resizeImage (testImageNameFailure , testImageWidth , testImageHeight ) ).toBeRejected(); |
88 | | - |
89 | | - }); |
90 | | - it ('1.2 The getImageMetaData function,Wrong image name .toBeRejected ',async ()=>{ |
91 | | - |
92 | | - await expectAsync( getImageMetaData ( testImageNameFailure ) ).toBeRejected(); |
93 | | - |
| 106 | + const testImageNameFailure = 'fjod'; |
| 107 | + const testImageWidth = 1500; |
| 108 | + const testImageHeight = 1500; |
| 109 | + it('1.1 The resizeImage function,Wrong image name .toBeRejected ', async () => { |
| 110 | + await expectAsync( |
| 111 | + resizeImage(testImageNameFailure, testImageWidth, testImageHeight) |
| 112 | + ).toBeRejected(); |
| 113 | + }); |
| 114 | + it('1.2 The getImageMetaData function,Wrong image name .toBeRejected ', async () => { |
| 115 | + await expectAsync( |
| 116 | + getImageMetaData(testImageNameFailure) |
| 117 | + ).toBeRejected(); |
94 | 118 | }); |
95 | 119 | }); |
96 | 120 |
|
97 | | -describe('these tests are focused at the createImage middleware at the middleware/api.image.Middleware/createImage.ts ' , ()=>{ |
98 | | - |
99 | | - const queriesSchema = { |
100 | | - AllCorrect : '?name=encenadaport&width=407&height=365', |
101 | | - nameAndWidthAndHeightWrong : '?name=ahmedzein&width=500&height=1000' |
| 121 | +describe('these tests are focused at the createImage middleware at the middleware/api.image.Middleware/createImage.ts ', () => { |
| 122 | + const queriesSchema = { |
| 123 | + AllCorrect: '?name=encenadaport&width=407&height=365', |
| 124 | + nameAndWidthAndHeightWrong: '?name=ahmedzein&width=500&height=1000', |
102 | 125 | }; |
103 | 126 |
|
104 | | - it( '1.1 All query values are Correct status code Equal to 200' , async () => { |
105 | | - const responseObject = await response.get (`/api/image${queriesSchema.AllCorrect}`); |
106 | | - expect( responseObject.status ).toEqual (200); |
| 127 | + it('1.1 All query values are Correct status code Equal to 200', async () => { |
| 128 | + const responseObject = await response.get( |
| 129 | + `/api/image${queriesSchema.AllCorrect}` |
| 130 | + ); |
| 131 | + expect(responseObject.status).toEqual(200); |
107 | 132 | }); |
108 | | - it( '1.2 All query values are Wrong Equal 404 resource was not found' , async () => { |
109 | | - const responseObject = await response.get (`/api/image${queriesSchema.nameAndWidthAndHeightWrong}`); |
110 | | - expect( responseObject.status ).toEqual (404); |
| 133 | + it('1.2 All query values are Wrong Equal 404 resource was not found', async () => { |
| 134 | + const responseObject = await response.get( |
| 135 | + `/api/image${queriesSchema.nameAndWidthAndHeightWrong}` |
| 136 | + ); |
| 137 | + expect(responseObject.status).toEqual(404); |
111 | 138 | }); |
112 | 139 | }); |
0 commit comments