-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance NewsArticleJsonLd and ArticleJsonLd author (#1105)
- Loading branch information
Showing
4 changed files
with
87 additions
and
14 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
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 { ArticleAuthor } from 'src/types'; | ||
import { setAuthor } from '../setAuthor'; | ||
|
||
describe('setAuthor', () => { | ||
test('should return undefined if author is undefined', () => { | ||
expect(setAuthor(undefined)).toBeUndefined(); | ||
}); | ||
|
||
test('works correctly when ArticleAuthor is passed', () => { | ||
const author: ArticleAuthor = { | ||
name: 'Acme', | ||
type: 'Organization', | ||
url: '/acme', | ||
}; | ||
|
||
const data = setAuthor(author); | ||
|
||
expect(data).toEqual({ | ||
'@type': 'Organization', | ||
name: 'Acme', | ||
url: '/acme', | ||
}); | ||
}); | ||
|
||
test('works correctly when just ArticleAuthor name is passed', () => { | ||
const data = setAuthor({ name: 'John Doe' }); | ||
|
||
expect(data).toEqual({ | ||
'@type': 'Person', | ||
name: 'John Doe', | ||
}); | ||
}); | ||
|
||
test('works correctly when an array of ArticleAuthor is passed', () => { | ||
const author: ArticleAuthor[] = [ | ||
{ | ||
name: 'Acme', | ||
type: 'Organization', | ||
url: '/acme', | ||
}, | ||
{ name: 'John Doe' }, | ||
]; | ||
|
||
const data = setAuthor(author); | ||
|
||
expect(data).toEqual([ | ||
{ | ||
'@type': 'Organization', | ||
name: 'Acme', | ||
url: '/acme', | ||
}, | ||
{ '@type': 'Person', name: 'John Doe' }, | ||
]); | ||
}); | ||
|
||
test('works correctly when string is passed', () => { | ||
const data = setAuthor('John Doe'); | ||
|
||
expect(data).toEqual({ | ||
'@type': 'Person', | ||
name: 'John Doe', | ||
}); | ||
}); | ||
|
||
test('works correctly when an array string is passed', () => { | ||
const data = setAuthor(['John Doe', 'Foo Bar']); | ||
|
||
expect(data).toEqual([ | ||
{ | ||
'@type': 'Person', | ||
name: 'John Doe', | ||
}, | ||
{ | ||
'@type': 'Person', | ||
name: 'Foo Bar', | ||
}, | ||
]); | ||
}); | ||
}); |
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