From c6df7f757177247d1ebce8601d2091177f513fd0 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Sat, 13 Apr 2024 15:15:05 -0400 Subject: [PATCH 1/9] started adding data for testing --- FU.SPA/tests/setup-tests.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index 04848af3..ea57f46f 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -6,9 +6,23 @@ const API_BASE_URL = process.env.API_BASE_URL; const setup = async () => { console.log('Setting up'); - - const response = await fetch(`${API_BASE_URL}/Games`); - console.log(await response.json()); + const gameData = { + name: "Insurgency", + id: "1" + }; + try { + const response = await fetch(`${API_BASE_URL}/Games`, { + method: 'POST', + headers: { + 'content-type': 'application/json', + }, + body: JSON.stringify(gameData), + }); + const result = await response.json(); + console.log('Data inserted:', result); + } catch (error) { + console.error('Failed to insert data:', error); + } console.log('Setup done'); }; From be3a609179b0c792b82f9aa836cefb5fb0476fb3 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Wed, 17 Apr 2024 22:19:39 -0400 Subject: [PATCH 2/9] stores auth token to post game data --- FU.SPA/tests/setup-tests.js | 92 ++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 17 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index ea57f46f..16d6ba32 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -4,28 +4,86 @@ console.log('Entering setup script'); const API_BASE_URL = process.env.API_BASE_URL; +let tokenStorage = {}; + +const signUp = async (credentials) => { + const response = await fetch(`${API_BASE_URL}/Accounts`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(credentials) + }); + + if (!response.ok) { + console.log('Response Status:', response.status); + const errorText = await response.text(); + console.error('Sign-up Error Response:', errorText); + throw new Error(`Failed to sign up: ${errorText}`); + } + + console.log('Sign-up successful.'); +}; + +// sign in and retrieve a token +const signIn = async (credentials) => { + const response = await fetch(`${API_BASE_URL}/Accounts/auth`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(credentials) + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Authentication failed: ${errorText}`); + } + + const data = await response.json(); + tokenStorage.token = data.token; + console.log('Authentication successful, token obtained.'); + return data.token; +}; + +const postGameData = async (gameData) => { + const token = tokenStorage.token; + const response = await fetch(`${API_BASE_URL}/Games`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}` + }, + body: JSON.stringify(gameData) + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Failed to post game data: ${errorText}`); + } + + const result = await response.json(); + console.log('Game data inserted:', result); +}; + const setup = async () => { - console.log('Setting up'); - const gameData = { - name: "Insurgency", - id: "1" - }; + console.log('setting up'); try { - const response = await fetch(`${API_BASE_URL}/Games`, { - method: 'POST', - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify(gameData), - }); - const result = await response.json(); - console.log('Data inserted:', result); + const credentials = { username: 'user', password: 'pass', email: 'user@example.com' }; + + await signUp(credentials); + await signIn(credentials); + const gameData = [ + { name: "Insurgency", id: "1" }, + { name: "RainBow Six Siege", id: "2" }, + { name: "Rocket League", id: "3" } + ]; + + for (const game of gameData) { + await postGameData(game); + } } catch (error) { - console.error('Failed to insert data:', error); + console.error('Setup failed:', error); } - console.log('Setup done'); + console.log('Setup complete'); }; -// Run setup after 3 second delay to give api time to startup +// Run the setup after a delay to give the API time to start up setTimeout(setup, 3000); From 2cc88e8ede41133db1065d0183f2666c7cbe135e Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Thu, 18 Apr 2024 01:29:29 -0400 Subject: [PATCH 3/9] added tags, more games, and create post data/API call --- FU.SPA/tests/setup-tests.js | 85 ++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index 16d6ba32..a9fa93d4 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -48,7 +48,7 @@ const postGameData = async (gameData) => { method: 'POST', headers: { 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}` + 'Authorization': `Bearer ${token}`, }, body: JSON.stringify(gameData) }); @@ -62,6 +62,57 @@ const postGameData = async (gameData) => { console.log('Game data inserted:', result); }; +const postTagData = async (tagData) => { + const token = tokenStorage.token; + const response = await fetch(`${API_BASE_URL}/Tags`, { + method: 'POST', + headers: { + 'content-type': 'application/json', + 'Authorization': `Bearer ${token}`, + }, + body: JSON.stringify(tagData), + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Failed to post tag data: ${errorText}`); + } + + const result = await response.json(); + console.log('Tag data inserted:', result); +}; + + +const createPost = async (postData) => { + const token = tokenStorage.token; + + if (postData.StartTime && postData.EndTime) { + postData.StartTime = new Date(postData.StartTime).toISOString(); + postData.EndTime = new Date(postData.EndTime).toISOString(); + } else { + console.error("Invalid or missing date fields"); + throw new Error("Invalid or missing date fields"); + } + + const response = await fetch(`${API_BASE_URL}/Posts`, { + method: 'POST', + headers: { + 'content-type': 'application/json', + 'Authorization': `Bearer ${token}`, + }, + body: JSON.stringify(postData), + }); + + if (!response.ok) { + const errorText = await response.text(); + console.error(`Failed to create post data: ${errorText}`); + throw new Error(`Failed to create post data: ${errorText}`); + } + + const result = await response.json(); + console.log('post data inserted:', result); +}; + const setup = async () => { console.log('setting up'); try { @@ -69,15 +120,44 @@ const setup = async () => { await signUp(credentials); await signIn(credentials); + const gameData = [ { name: "Insurgency", id: "1" }, { name: "RainBow Six Siege", id: "2" }, - { name: "Rocket League", id: "3" } + { name: "Rocket League", id: "3" }, + { name: "Call of Duty", id: "4" }, + { name: "Counter Strike 2", id: "5" } + ]; + + const tagData = [ + { name: "mic", id: "1" }, + { name: "fun", id: "2"}, + { name: "casual", id: "3"}, + { name: "east", id: "4"}, + { name: "open", id: "5"} ]; + const postData = { + Title: "Exciting Game Night", + Description: "Join us for an exciting night of gaming!", + GameId: 1, + StartTime: "2024-07-20T18:00:00", + EndTime: "2024-07-20T21:00:00", + MaxPlayers: 10, + TagIds: [1, 3, 5] + }; + + for (const game of gameData) { await postGameData(game); } + + for (const tag of tagData) { + await postTagData(tag); + } + + await createPost(postData); + } catch (error) { console.error('Setup failed:', error); } @@ -85,5 +165,6 @@ const setup = async () => { console.log('Setup complete'); }; + // Run the setup after a delay to give the API time to start up setTimeout(setup, 3000); From e7471ad6c27b9f1ef89ea2e9750e00da08c3fcc6 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Thu, 18 Apr 2024 23:32:48 -0400 Subject: [PATCH 4/9] add more users --- FU.SPA/tests/setup-tests.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index a9fa93d4..d7ef4781 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -116,11 +116,21 @@ const createPost = async (postData) => { const setup = async () => { console.log('setting up'); try { - const credentials = { username: 'user', password: 'pass', email: 'user@example.com' }; - - await signUp(credentials); - await signIn(credentials); + + const numberOfUsers = 25; +const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ + username: `user${i + 1}`, + password: `password${i + 1}`, + email: `user${i + 1}@example.com` +})); + + for(const user of credentials) { + await signUp(user); + } + for(const user of credentials) { + await signIn(user); + } const gameData = [ { name: "Insurgency", id: "1" }, { name: "RainBow Six Siege", id: "2" }, From 62febfa3d699b76233157863c0fe3af1b1b6e5cc Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Fri, 19 Apr 2024 00:04:04 -0400 Subject: [PATCH 5/9] generates 48 test post templates --- FU.SPA/tests/setup-tests.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index d7ef4781..3b8835e1 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -147,15 +147,17 @@ const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ { name: "open", id: "5"} ]; - const postData = { - Title: "Exciting Game Night", - Description: "Join us for an exciting night of gaming!", - GameId: 1, - StartTime: "2024-07-20T18:00:00", - EndTime: "2024-07-20T21:00:00", - MaxPlayers: 10, - TagIds: [1, 3, 5] - }; + const NewPostData = (index) => { + return { + Title: `Exciting Game Night ${index}`, + Description: `Join us for an exciting night of gaming at event ${index}!`, + GameId: (index % 5) + 1, + StartTime: `2024-07-${20 + (index % 2)}T18:00:00`, + EndTime: `2024-07-${20 + (index % 2)}T21:00:00`, + MaxPlayers: 10 + (index % 10), + TagIds: [(index % 5) + 1, ((index + 1) % 5) + 1, ((index + 2) % 5) + 1] + }; + }; for (const game of gameData) { @@ -166,7 +168,20 @@ const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ await postTagData(tag); } - await createPost(postData); +// Function to post all generated posts +const AllGeneratedPosts = async () => { + for (let i = 0; i < 48; i++) { + const postData = NewPostData(i + 1); + try { + await createPost(postData); + console.log(`Post ${i + 1} created successfully.`); + } catch (error) { + console.error(`Failed to create post ${i + 1}:`, error); + } + } +}; + +AllGeneratedPosts(); } catch (error) { console.error('Setup failed:', error); From 77c24cc57e7e594102e0a4a9547d57251ab4ebc3 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Fri, 19 Apr 2024 00:31:24 -0400 Subject: [PATCH 6/9] added more variety to the posts dates and times for filtering test. Also ran format --- FU.SPA/tests/setup-tests.js | 108 +++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index 3b8835e1..a59c57e7 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -10,7 +10,7 @@ const signUp = async (credentials) => { const response = await fetch(`${API_BASE_URL}/Accounts`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(credentials) + body: JSON.stringify(credentials), }); if (!response.ok) { @@ -28,7 +28,7 @@ const signIn = async (credentials) => { const response = await fetch(`${API_BASE_URL}/Accounts/auth`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(credentials) + body: JSON.stringify(credentials), }); if (!response.ok) { @@ -48,9 +48,9 @@ const postGameData = async (gameData) => { method: 'POST', headers: { 'Content-Type': 'application/json', - 'Authorization': `Bearer ${token}`, + Authorization: `Bearer ${token}`, }, - body: JSON.stringify(gameData) + body: JSON.stringify(gameData), }); if (!response.ok) { @@ -68,7 +68,7 @@ const postTagData = async (tagData) => { method: 'POST', headers: { 'content-type': 'application/json', - 'Authorization': `Bearer ${token}`, + Authorization: `Bearer ${token}`, }, body: JSON.stringify(tagData), }); @@ -82,7 +82,6 @@ const postTagData = async (tagData) => { console.log('Tag data inserted:', result); }; - const createPost = async (postData) => { const token = tokenStorage.token; @@ -90,15 +89,15 @@ const createPost = async (postData) => { postData.StartTime = new Date(postData.StartTime).toISOString(); postData.EndTime = new Date(postData.EndTime).toISOString(); } else { - console.error("Invalid or missing date fields"); - throw new Error("Invalid or missing date fields"); + console.error('Invalid or missing date fields'); + throw new Error('Invalid or missing date fields'); } const response = await fetch(`${API_BASE_URL}/Posts`, { method: 'POST', headers: { 'content-type': 'application/json', - 'Authorization': `Bearer ${token}`, + Authorization: `Bearer ${token}`, }, body: JSON.stringify(postData), }); @@ -116,50 +115,57 @@ const createPost = async (postData) => { const setup = async () => { console.log('setting up'); try { - - const numberOfUsers = 25; + const numberOfUsers = 25; -const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ - username: `user${i + 1}`, - password: `password${i + 1}`, - email: `user${i + 1}@example.com` -})); + const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ + username: `user${i + 1}`, + password: `password${i + 1}`, + email: `user${i + 1}@example.com`, + })); - for(const user of credentials) { - await signUp(user); - } - for(const user of credentials) { - await signIn(user); - } + for (const user of credentials) { + await signUp(user); + } + for (const user of credentials) { + await signIn(user); + } const gameData = [ - { name: "Insurgency", id: "1" }, - { name: "RainBow Six Siege", id: "2" }, - { name: "Rocket League", id: "3" }, - { name: "Call of Duty", id: "4" }, - { name: "Counter Strike 2", id: "5" } + { name: 'Insurgency', id: '1' }, + { name: 'RainBow Six Siege', id: '2' }, + { name: 'Rocket League', id: '3' }, + { name: 'Call of Duty', id: '4' }, + { name: 'Counter Strike 2', id: '5' }, ]; - const tagData = [ - { name: "mic", id: "1" }, - { name: "fun", id: "2"}, - { name: "casual", id: "3"}, - { name: "east", id: "4"}, - { name: "open", id: "5"} + const tagData = [ + { name: 'mic', id: '1' }, + { name: 'fun', id: '2' }, + { name: 'casual', id: '3' }, + { name: 'east', id: '4' }, + { name: 'open', id: '5' }, ]; const NewPostData = (index) => { + const month = Math.floor(Math.random() * 12) + 1; + const day = Math.floor(Math.random() * 28) + 1; + const hourStart = Math.floor(Math.random() * 5) + 16; + const hourEnd = hourStart + Math.floor(Math.random() * 3) + 1; + return { Title: `Exciting Game Night ${index}`, Description: `Join us for an exciting night of gaming at event ${index}!`, GameId: (index % 5) + 1, - StartTime: `2024-07-${20 + (index % 2)}T18:00:00`, - EndTime: `2024-07-${20 + (index % 2)}T21:00:00`, + StartTime: `2024-${month.toString().padStart(2, '0')}-${day + .toString() + .padStart(2, '0')}T${hourStart.toString().padStart(2, '0')}:00:00`, + EndTime: `2024-${month.toString().padStart(2, '0')}-${day + .toString() + .padStart(2, '0')}T${hourEnd.toString().padStart(2, '0')}:00:00`, MaxPlayers: 10 + (index % 10), - TagIds: [(index % 5) + 1, ((index + 1) % 5) + 1, ((index + 2) % 5) + 1] + TagIds: [(index % 5) + 1, ((index + 1) % 5) + 1, ((index + 2) % 5) + 1], }; }; - for (const game of gameData) { await postGameData(game); } @@ -168,21 +174,20 @@ const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ await postTagData(tag); } -// Function to post all generated posts -const AllGeneratedPosts = async () => { - for (let i = 0; i < 48; i++) { - const postData = NewPostData(i + 1); - try { - await createPost(postData); - console.log(`Post ${i + 1} created successfully.`); - } catch (error) { - console.error(`Failed to create post ${i + 1}:`, error); - } - } -}; - -AllGeneratedPosts(); + // Function to post all generated posts + const AllGeneratedPosts = async () => { + for (let i = 0; i < 48; i++) { + const postData = NewPostData(i + 1); + try { + await createPost(postData); + console.log(`Post ${i + 1} created successfully.`); + } catch (error) { + console.error(`Failed to create post ${i + 1}:`, error); + } + } + }; + AllGeneratedPosts(); } catch (error) { console.error('Setup failed:', error); } @@ -190,6 +195,5 @@ AllGeneratedPosts(); console.log('Setup complete'); }; - // Run the setup after a delay to give the API time to start up setTimeout(setup, 3000); From d0a39d7a55cf6deffe761c2cb46a405482115cc0 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Fri, 19 Apr 2024 16:17:45 -0400 Subject: [PATCH 7/9] updated time and date, prevents from making dates in the past --- FU.SPA/tests/setup-tests.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index a59c57e7..af81cf27 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -146,19 +146,31 @@ const setup = async () => { ]; const NewPostData = (index) => { - const month = Math.floor(Math.random() * 12) + 1; - const day = Math.floor(Math.random() * 28) + 1; + const currentDate = new Date(); + const currentYear = currentDate.getFullYear(); + const currentMonth = currentDate.getMonth() + 1; + const currentDay = currentDate.getDate(); + + const month = Math.floor(Math.random() * (12 - currentMonth + 1)) + currentMonth; + + let day; + if (month === currentMonth) { + day = Math.floor(Math.random() * (28 - currentDay)) + currentDay + 1; + } else { + day = Math.floor(Math.random() * 28) + 1; + } + const hourStart = Math.floor(Math.random() * 5) + 16; const hourEnd = hourStart + Math.floor(Math.random() * 3) + 1; - + return { Title: `Exciting Game Night ${index}`, Description: `Join us for an exciting night of gaming at event ${index}!`, GameId: (index % 5) + 1, - StartTime: `2024-${month.toString().padStart(2, '0')}-${day + StartTime: `${currentYear}-${month.toString().padStart(2, '0')}-${day .toString() .padStart(2, '0')}T${hourStart.toString().padStart(2, '0')}:00:00`, - EndTime: `2024-${month.toString().padStart(2, '0')}-${day + EndTime: `${currentYear}-${month.toString().padStart(2, '0')}-${day .toString() .padStart(2, '0')}T${hourEnd.toString().padStart(2, '0')}:00:00`, MaxPlayers: 10 + (index % 10), From 7b5622ea7ff68eccd732000df8990b185f6f886d Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Fri, 19 Apr 2024 16:18:20 -0400 Subject: [PATCH 8/9] format --- FU.SPA/tests/setup-tests.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index af81cf27..4716f84c 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -150,19 +150,20 @@ const setup = async () => { const currentYear = currentDate.getFullYear(); const currentMonth = currentDate.getMonth() + 1; const currentDay = currentDate.getDate(); - - const month = Math.floor(Math.random() * (12 - currentMonth + 1)) + currentMonth; - + + const month = + Math.floor(Math.random() * (12 - currentMonth + 1)) + currentMonth; + let day; if (month === currentMonth) { day = Math.floor(Math.random() * (28 - currentDay)) + currentDay + 1; } else { day = Math.floor(Math.random() * 28) + 1; } - + const hourStart = Math.floor(Math.random() * 5) + 16; const hourEnd = hourStart + Math.floor(Math.random() * 3) + 1; - + return { Title: `Exciting Game Night ${index}`, Description: `Join us for an exciting night of gaming at event ${index}!`, From 18e7cd090ff5a6a18f8fecc19c5416c40ef76d96 Mon Sep 17 00:00:00 2001 From: Jackson Williams Date: Sun, 21 Apr 2024 00:15:35 -0400 Subject: [PATCH 9/9] added special character to password --- FU.SPA/tests/setup-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FU.SPA/tests/setup-tests.js b/FU.SPA/tests/setup-tests.js index 4716f84c..8ae1dfe4 100644 --- a/FU.SPA/tests/setup-tests.js +++ b/FU.SPA/tests/setup-tests.js @@ -119,7 +119,7 @@ const setup = async () => { const credentials = Array.from({ length: numberOfUsers }, (v, i) => ({ username: `user${i + 1}`, - password: `password${i + 1}`, + password: `pass_word${i + 1}`, email: `user${i + 1}@example.com`, }));