Skip to content

Commit

Permalink
Improve code docs with gpt4
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Aug 3, 2024
1 parent 7e557ca commit 816b383
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 45 deletions.
17 changes: 13 additions & 4 deletions Sources/MockGen/MockGen+Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import FileSugar
extension MockGen {
/**
* Random bank name
* - Description: This method generates a random bank name from the `Banks` array. If the array is empty, the method returns `nil`.
*/
public static var randomBank: String? { Banks.line }
/**
* Random note
* - Description: This method generates a random note from the `Notes` array. If the array is empty, the method returns `nil`.
*/
public static var randomNote: String? { Notes.line }
/**
* Random full name
* - Description: This method generates a random full name from the `Names` array. If the array is empty, the method returns `nil`.
* - Fixme: ⚠️️ Create firstNames, lastNames, fullNames? this is now in use MockGen.randomFirstName etc
*/
public static var randomFullName: String? { Names.line }
Expand All @@ -27,31 +30,36 @@ extension MockGen {
extension MockGen {
/**
* Random SSID generator
* - Description: Generates a random SSID for use in testing network-related functionalities. The SSID is selected from a predefined list of common Wi-Fi network names.
* - Note: This method generates a random SSID from the `SSIDS` array, which contains a list of common wifi network names. If the array is empty, the method returns `nil`.
* - Returns: A random SSID string from the `SSIDS` array, or `nil` if the array is empty.
*/
public static var randomSSID: String? { SSIDS.line }
/**
* Random credit card issuer generator
* - Description: This method generates a random credit card issuer name from a predefined list, aiding in the testing of payment processing systems.
* - Note: This method generates a random credit card issuer name from the `CreditCardIssuers` array, which contains a list of common credit card issuers. If the array is empty, the method returns `nil`.
* - Returns: A random credit card issuer name string from the `CreditCardIssuers` array, or `nil` if the array is empty.
*/
public static var randomIssuer: String? { CreditCardIssuers.line }
/**
* Random brand name generator
* - Description: This method generates a random brand name from the `Brands` array, which contains a list of common brand names. If the array is empty, the method returns `nil`.
* - Note: This method generates a random brand name from the `Brands` array, which contains a list of common brand names. If the array is empty, the method returns `nil`.
* - Returns: A random brand name string from the `Brands` array, or `nil` if the array is empty.
*/
public static var randomBrand: String? { Brands.brands.randomElement() }
/**
* Random email
* - Description: This method generates a random email by combining a random first name and a random brand name. If either the first name or brand name cannot be generated, the method returns `nil`.
*/
public static var randomEmail: String? {
guard let name: String = randomFirstName,
let brand: String = randomBrand else { return nil }
return getEmail(name: name, brand: brand)
}
/**
* - Description: This method generates a random OTP (One-Time Password) for testing purposes. It uses a predefined format and a randomly generated secret to create the OTP. The secret is an uppercase string generated by the CodeGen class. The OTP is returned as a string in the format of a URL, which can be used to test OTP-related functionalities.
* - Remark: Secret has a format behind it. Uppercase random string seems to work
* - Fixme: ⚠️️⚠️️ We should also add other random elements to the OTP url later 👈
* - Fixme: ⚠️️ Maybe use TWOFA lib to gen the secret? we cant access seclib here so no, using SecRan.randomSecret should work better
Expand All @@ -73,25 +81,26 @@ extension MockGen {
}
/**
* Random boolean generators
* These methods generate random boolean values with different probabilities of being true, such as 1/8, 1/16, and 1/32. The methods use the `getRandomBool` method to generate the boolean values with the specified probability.
* - Description: This section contains methods that generate random boolean values with varying probabilities. These methods are useful for simulating different scenarios in testing, such as the likelihood of an item being marked as a favorite, archived, or moved to the trash.
* - Note: These methods generate random boolean values with different probabilities of being true, such as 1/8, 1/16, and 1/32. The methods use the `getRandomBool` method to generate the boolean values with the specified probability.
* - Note: These methods are marked as `internal` to ensure they can only be accessed within the same module.
*/
extension MockGen {
/**
* Random favorite boolean
*
* - Description: This method generates a random boolean value that represents a user's preference, such as marking an item as a favorite. The method has a higher probability of returning `false` to simulate a more realistic scenario where not all items are marked as favorites.
* - Returns: A random boolean value with a 1/8 probability of being true.
*/
public static var randomFavorite: Bool { getRandomBool(3) } // 1 / 8
/**
* Random archive boolean
*
* - Description: This method generates a random boolean value with a 1/16 probability of being true, which can be used to simulate the chance of an item being archived in various testing scenarios.
* - Returns: A random boolean value with a 1/16 probability of being true.
*/
public static var randomArchive: Bool { getRandomBool(4) } // 1 / 16
/**
* Random trash boolean
*
* - Description: This method generates a random boolean value with a 1/32 probability of being true, simulating the chance of an item being moved to the trash in a random scenario.
* - Returns: A random boolean value with a 1/32 probability of being true.
*/
public static var randomTrash: Bool { getRandomBool(5) } // 1 / 32
Expand Down
11 changes: 4 additions & 7 deletions Sources/MockGen/MockGen+Getter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import Foundation
/**
* Email and website mock generators
* - Description: This section contains methods for generating mock email addresses and website URLs, which are essential for testing email and web-related functionalities in applications.
* - Note: These methods generate mock email addresses and website URLs based on the specified name and brand. The `getEmail` method combines the lowercased name and website into an email address, while the `getWebsite` method returns the website for the specified brand. The `websites` dictionary contains a list of common brand names and their associated websites.
* - Note: These methods are marked as `internal` to ensure they can only be accessed within the same module.
*/
extension MockGen {
/**
* Email mock generator
* - Description: Generates a mock email address by concatenating the provided name and brand with the domain obtained from the `getWebsite` method. The name is converted to lowercase to simulate a typical email format.
* - Parameters:
* - name: The name to use in the email address.
* - brand: The brand to use in the email address.
Expand All @@ -19,6 +21,7 @@ extension MockGen {
}
/**
* Website mock generator
* - Description: This method generates a mock website URL for a given brand. It looks up the brand in the `Websites` dictionary to find the associated website. If the brand is not present in the dictionary, it logs an error and returns `nil`.
* - Parameter brand: The brand to use in the website URL.
* - Returns: A mock website URL string based on the specified brand, or `nil` if the website for the brand is not found.
*/
Expand All @@ -31,6 +34,7 @@ extension MockGen {
}
/**
* Random first name
* - Description: This method generates a random first name by extracting the first part of a random full name. If no full name is available or the name cannot be split, it logs an error and returns `nil`.
* - Fixme: ⚠️️ Add random last name?
*/
public static var randomFirstName: String? {
Expand All @@ -42,11 +46,4 @@ extension MockGen {
return String(first)
}
}
// deprecated ⚠️️
//extension MockGen {
// @available(*, deprecated, renamed: "randomFirstName") // You can also point to new class : "UIAlertController.createAlert"
// static var randomName: String? {
// randomFirstName
// }
//}
#endif
6 changes: 4 additions & 2 deletions Sources/MockGen/MockGen+Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import CryptoKit
import JSONSugar
import FileSugar
/**
* Utility methods
* - Description: These methods provide utility functionality for `MockGen`, such as generating random dates and boolean values with different probabilities of being true.
* These methods provide utility functionality for `MockGen`, such as generating random dates and boolean values with different probabilities of being true.
* - Description: The utility methods in this extension are designed to assist in the creation of mock data by providing random date and boolean value generation. These methods are particularly useful for testing scenarios that require data variability.
* - Note: These methods are marked as `internal` to ensure they can only be accessed within the same module. They are also wrapped in a `DEBUG` conditional compilation block to ensure they are only included in debug builds.
*/
extension MockGen {
/**
* Random date generator
* - Description: Generates a random date within a specified range of milliseconds. This method is useful for creating date data for testing purposes, ensuring variability in the generated dates.
* ## Examples:
* let randomDate = MockGen.randomDate // "06/23/2022"
* - Returns: A random date string in the short date format (MM/dd/yyyy)
Expand All @@ -22,6 +23,7 @@ extension MockGen {
}
/**
* Random boolean generator
* - Description: This method provides a way to generate a boolean value based on a given chance. The higher the `chance` parameter value, the lower the probability of the method returning `true`. This is useful for simulating conditions with varying likelihoods in testing scenarios.
* - Parameter chance: The probability of the boolean value being true, expressed as an integer where 1/chance is the probability (e.g. 3 = 1/16th chance, 4 = 1/32th chance).
* - Returns: A random boolean value with the specified probability of being true
* ## Examples:
Expand Down
2 changes: 1 addition & 1 deletion Sources/MockGen/MockGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import CryptoKit // Provides cryptographic functionality for generating secure r
import JSONSugar // Provides convenience methods for working with JSON data
import FileSugar // Provides convenience methods for working with files and directories
/**
* MockGen
* This class is used for generating mock data for unit tests. It includes methods for generating random passwords, as well as adding user names, emails, and notes via JSON files. It's currently only used for debugging purposes, but could potentially be spun out into its own repository or framework and launched on a platform like Product Hunt.
* - Description: MockGen is a utility class used for generating mock data for unit tests. It can generate random passwords and add user names, emails, and notes via JSON files. Currently, it is used for debugging purposes but has the potential to be developed into a standalone repository or framework.
* - Note: We can use this in other frameworks if we use `@testable import Account`
* - Fixme: ⚠️️ Add the random password methods from `UITests`. (or move them?)
* - Fixme: ⚠️️ Consider spinning MockGen out into its own repository or framework. (We can make the account an extension in the account lib etc)
Expand Down
7 changes: 4 additions & 3 deletions Sources/MockGen/assets/Banks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import Foundation

/**
* Banks CSV data
*
* This class provides access to the list of banks stored in a CSV file. The `lines` property contains an array of strings, where each string represents a line in the CSV file. The `fileName` property specifies the name of the CSV file to load.
*
* - Description: This class represents a collection of banks, providing access to a list of bank information stored in a CSV file.
* It is designed to be used for generating mock data or testing scenarios related to banking operations.
* The class conforms to the CSVKind protocol, which defines the structure for accessing CSV-based data.
* - Note: This class provides access to the list of banks stored in a CSV file. The `lines` property contains an array of strings, where each string represents a line in the CSV file. The `fileName` property specifies the name of the CSV file to load.
* - Note: This class is only available in DEBUG builds.
*/
class Banks: CSVKind {
Expand Down
5 changes: 5 additions & 0 deletions Sources/MockGen/assets/Brands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import JSONSugar
import Logger
/**
* Brands
* - Description: This enum provides access to a list of brand names and associated functionality.
* It loads brand names from a JSON file and offers methods to retrieve and work with these brands.
* - Remark: These types have accociated icon graphic
*/
public enum Brands {
/**
* Brands
* - Description: This static property holds an array of brand names loaded from a JSON file.
* It provides a centralized list of brands that can be used throughout the application.
* The brands are sorted alphabetically for easy access and consistency.
* - Remark: These types have associated icon graphic
* - Remark: We store the brands in an array to avoid loading them repeatedly.
* - Remark: We cannot use `Config.Bundle.assets` for this purpose.
Expand Down
4 changes: 3 additions & 1 deletion Sources/MockGen/assets/CreditIssuers.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#if DEBUG
import Foundation

/**
* CreditCardIssuers
* - Description: This class represents a collection of credit card issuers, providing access to a list of issuers stored in a CSV file.
* It is designed to be used for generating mock data or testing scenarios related to credit card operations.
* The class conforms to the CSVKind protocol, which defines the structure for accessing CSV-based data.
* - Remark: This class provides a list of credit card issuers for use in testing and debugging.
* - Remark: The list is loaded from a CSV file named "CreditIssuers.csv".
* - Note: The file should be located in the module's resource path.
Expand Down
6 changes: 5 additions & 1 deletion Sources/MockGen/assets/Names.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#if DEBUG
import Foundation

/**
* A class that provides access to a list of names from a CSV file in the debug build.
* - Description: This class provides access to a list of names stored in a CSV file.
* It is designed to be used for generating mock data or testing scenarios that require
* realistic person names, genders, ages, and occupations. The class conforms to the
* CSVKind protocol, which defines the structure for accessing CSV-based data.
* - Note: This class is only available in DEBUG builds to ensure it's not included in production code.
*/
class Names: CSVKind {
/**
Expand Down
4 changes: 2 additions & 2 deletions Sources/MockGen/assets/Notes.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if DEBUG
import Foundation

/*
/**
* Notes is a class that represents a CSV file containing notes.
* It conforms to the CSVKind protocol, which defines methods for working with CSV files.
* - Description: This class provides access to a list of notes stored in a CSV file. It is designed to be used for managing and retrieving note entries efficiently for testing or development purposes.
*/
class Notes: CSVKind {
/*
Expand Down
6 changes: 5 additions & 1 deletion Sources/MockGen/assets/Websites.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import FileSugar // Provides a collection of file and directory utilities.
import JSONSugar // Provides a collection of JSON utilities.
/**
* Websites
* - Description: This enum provides a centralized access point for retrieving website URLs associated with different companies. It supports adding custom brand-specific websites and allows overriding the default behavior to accommodate specific needs.
* - Fixme: ⚠️️ Make this a class that can be overriden
*/
public enum Websites {
/**
* A tuple representing a company and its associated website URL
* - Description: This tuple holds the company name and its corresponding website URL, facilitating easy access and management of web resources associated with different companies.
*/
public typealias Website = (company: String, website: String)
/**
* Returns the website URL for a given company name.
* - Description: This function retrieves the website URL associated with a specified company name by searching through a combined list of default and brand-specific websites.
* - Fixme: ⚠️️ This function is not currently overridable to add brand-specific websites. To make it overridable, refactor the function to use a protocol and provide a default implementation in an extension.
* ## Examples:
* website(company: "adobe") // Returns "adobe.com"
Expand All @@ -29,7 +32,7 @@ public enum Websites {
extension Websites {
/**
* Returns an array of `Website` tuples parsed from a CSV file.
* - Description: Provides website URLs for company names.
* - Description: This method loads and parses a CSV file containing company names and their associated website URLs into an array of `Website` tuples.
* - Remark: The `.csv` file will not parse as utf8, so we use roman, see https://stackoverflow.com/a/26454159/5389500 for more info.
* - Remark: The CSV file should have the following format:
* - The file is a CSV (comma-separated values) file.
Expand All @@ -49,6 +52,7 @@ extension Websites {
}()
/**
* Provides a description of the expected format of the `brandsites.csv` file.
* - Description: This section provides details about the `brandsites.csv` file used to store brand-specific website URLs. Each line in the CSV file represents a unique brand and its corresponding website URL, allowing for easy retrieval and management of brand-specific web resources.
* - Remark: The file is a CSV (comma-separated values) file.
* - Remark: Each line of the file represents a company and its associated website URL.
* - Remark: The company name and website URL are separated by a comma.
Expand Down
Loading

0 comments on commit 816b383

Please sign in to comment.