This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { expect } from 'vitest' | ||
import { injectSchemaOrg, useSchemaOrg, useSetup } from '../../../.test' | ||
import { defineSoftwareApp } from '#provider' | ||
|
||
describe('defineSoftwareApp', () => { | ||
it('can be defined', () => { | ||
useSetup(() => { | ||
useSchemaOrg([ | ||
defineSoftwareApp({ | ||
name: 'Angry Birds', | ||
operatingSystem: 'ANDROID', | ||
applicationCategory: 'GameApplication', | ||
aggregateRating: { | ||
ratingValue: '4.6', | ||
ratingCount: 8864, | ||
}, | ||
offers: { | ||
price: '1.00', | ||
priceCurrency: 'USD', | ||
}, | ||
}), | ||
]) | ||
|
||
const { graphNodes } = injectSchemaOrg() | ||
|
||
expect(graphNodes).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"@type": "SoftwareApplication", | ||
"aggregateRating": { | ||
"@type": "AggregateRating", | ||
"ratingCount": 8864, | ||
"ratingValue": "4.6", | ||
}, | ||
"applicationCategory": "GameApplication", | ||
"name": "Angry Birds", | ||
"offers": { | ||
"@type": "Offer", | ||
"availability": "https://schema.org/InStock", | ||
"price": "1.00", | ||
"priceCurrency": "USD", | ||
"priceValidUntil": "2023-12-30T00:00:00.000Z", | ||
}, | ||
"operatingSystem": "ANDROID", | ||
}, | ||
] | ||
`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import type { Arrayable, NodeRelation, NodeRelations, Thing } from '../../types' | ||
import { defineSchemaOrgResolver, resolveRelation } from '../../core' | ||
import type { Offer } from '../Offer' | ||
import { offerResolver } from '../Offer' | ||
import type { AggregateRating } from '../AggregateRating' | ||
import { aggregateRatingResolver } from '../AggregateRating' | ||
import type { Review } from '../Review' | ||
import { reviewResolver } from '../Review' | ||
import { resolveDefaultType } from '../../utils' | ||
|
||
type ApplicationCategory = | ||
'GameApplication' | | ||
'SocialNetworkingApplication' | | ||
'TravelApplication' | | ||
'ShoppingApplication' | | ||
'SportsApplication' | | ||
'LifestyleApplication' | | ||
'BusinessApplication' | | ||
'DesignApplication' | | ||
'DeveloperApplication' | | ||
'DriverApplication' | | ||
'EducationalApplication' | | ||
'HealthApplication' | | ||
'FinanceApplication' | | ||
'SecurityApplication' | | ||
'BrowserApplication' | | ||
'CommunicationApplication' | | ||
'DesktopEnhancementApplication' | | ||
'EntertainmentApplication' | | ||
'MultimediaApplication' | | ||
'HomeApplication' | | ||
'UtilitiesApplication' | | ||
'ReferenceApplication' | ||
|
||
export interface SoftwareAppLite extends Thing { | ||
'@type'?: Arrayable<'SoftwareApplication' | 'MobileApplication' | 'VideoGame' | 'WebApplication'> | ||
/** | ||
* The name of the app. | ||
*/ | ||
name?: string | ||
/** | ||
* An offer to sell the app. | ||
* For developers, offers can indicate the marketplaces that carry the application. | ||
* For marketplaces, use offers to indicate the price of the app for a specific app instance. | ||
*/ | ||
offers: NodeRelations<Offer> | ||
/** | ||
* The average review score of the app. | ||
*/ | ||
aggregateRating?: NodeRelation<AggregateRating> | ||
/** | ||
* A single review of the app. | ||
*/ | ||
review?: NodeRelation<Review> | ||
/** | ||
* The type of app (for example, BusinessApplication or GameApplication). The value must be a supported app type. | ||
*/ | ||
applicationCategory?: ApplicationCategory | ||
/** | ||
* The operating system(s) required to use the app (for example, Windows 7, OSX 10.6, Android 1.6) | ||
*/ | ||
operatingSystem?: string | ||
} | ||
|
||
export interface SoftwareApp extends SoftwareAppLite {} | ||
|
||
export const softwareAppResolver = defineSchemaOrgResolver<SoftwareApp>({ | ||
defaults: { | ||
'@type': 'SoftwareApplication', | ||
}, | ||
resolve(node, ctx) { | ||
resolveDefaultType(node, 'SoftwareApplication') | ||
node.offers = resolveRelation(node.offers, ctx, offerResolver) | ||
node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver) | ||
node.review = resolveRelation(node.review, ctx, reviewResolver) | ||
return node | ||
}, | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters